-
Notifications
You must be signed in to change notification settings - Fork 37
Longest Prefix Match #5
Comments
Its floorEntry(K key) that gives the right answer not getNearestEntryForKey. Example: floorEntry is also package protected but part of the NavigableMap interface. |
Calling that function actually causes a crash, because it modifies the map. Does anybody have another function which is safe to use instead? |
I implemented it like this, but I'm not sure it's right, if somebody can check my work I'm going to see about contributing it to the Apache version.
|
That code is definitely not equivalent to floorEntry(K key). From what I remember using floorEntry didn't cause a crash, but yes it modifies the trie (so its unsafe with concurrent access). |
Nice to see that people are using it. We contributed an earlier version/fork to Apache Commons and it got accepted in v4. If you're looking for a general purpose (Patricia) Trie then I'd look into that. |
I saw that. But I didn't see any methods for longest-prefix match. On Sat, Mar 8, 2014 at 12:41 PM, Roger Kapsi [email protected]:
|
In case anyone else is wondering how to get a longest prefix match with a
They are unfortunately only declared on |
In my tests, floorEntry doesn't return the longest prefix either. For example, if the trie contains EDIT I am talking about the code in Apache Commons (4.1), but from a quick look I think the code is the same. |
floorEntry has nothing in common with longest prefix, it can be uses only for initial approximation |
Given a trie with keys 'abc' 'abcde' & 'abcdefgh'
I wish to have a method which when given 'abcdefg'
returns the entry whose key is 'abcde'.
That is the entry whose key is the longest prefix matching the given string.
I have to do a bit of testing but I believe the method already exists.
AbstractPatriciaTrie.getNearestEntryForKey(Object key);
but it is declared package rather than public.
The text was updated successfully, but these errors were encountered: