Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with overflow bits in patricia trie #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ public boolean isSet(int bit, String key) {
return false;
}

if (bit >= length(key)) {
if (bit == length(key)) {
return false;
} else if (bit > length(key)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ public void testPrefix() {
assertTrue(trie.containsKeyPrefix("Fus"));
}

@Test
public void testOverflowBitsEdgeCase() {
PatriciaTrie<String> trie = new PatriciaTrie<>();
trie.put("a", "0");
trie.put("a\uFFFF", "1");
assertEquals("0", trie.get("a"));
assertEquals("1", trie.get("a\uFFFF"));
}

@Test
public void testTextScan() {
PatriciaTrie<String> trie = new PatriciaTrie<>();
Expand Down Expand Up @@ -400,7 +409,7 @@ public void testNullKeyMap() {
public void testEmptyKeyMap() {
PatriciaTrie.KeyMapper<String> keyMapper = new PatriciaTrie.StringKeyMapper();
// Note: this is a special case handled in PatriciaTrie
assertTrue(keyMapper.isSet(0, ""));
assertFalse(keyMapper.isSet(0, ""));
assertTrue(keyMapper.isSet(100, ""));
assertTrue(keyMapper.isSet(1000, ""));
}
Expand Down Expand Up @@ -431,8 +440,9 @@ public void testOverflowBit() {
assertFalse(keyMapper.isSet(14, key));
assertTrue(keyMapper.isSet(15, key));

// Asking for overflow bits should return 1
assertTrue(keyMapper.isSet(16, key));
// Asking for first overflow bit should return 0
assertFalse(keyMapper.isSet(16, key));
// Asking for other overflow bits should return 1
assertTrue(keyMapper.isSet(17, key));
assertTrue(keyMapper.isSet(100, key));
}
Expand Down