I am running into issues, where the prefix trie returns prefixes, that were never inserted.
I am running version 1.0.0
Here is my example code:
from ipprefixtrie import IPPrefixTrie
trie = IPPrefixTrie()
prefix = "129.69.0.0/16"
trie.insert(prefix)
result = trie.get_longest("129.69.138.161")[0]
print(result, prefix)
assert result == prefix, f"{result} != {prefix}"
This results in the following output:
129.69.128.0/16 129.69.0.0/16
Traceback (most recent call last):
File "<...>/test.py", line 11, in <module>
assert result == prefix, f"{result} != {prefix}"
^^^^^^^^^^^^^^^^
AssertionError: 129.69.128.0/16 != 129.69.0.0/16
A couple of other tests with different addresses show, that this appear to happen once the hightest bit of the third byte is set, e.g.:
- 129.69.38.0 works as intended
- 129.69.128.0 is wrong
- 129.69.255.161 is wrong