Hi Dusan,
This was a good suggestion, thanks. I have implemented it and released it as Concurrent-Trees 2.1.0. It should sync to Maven central in the next few hours.
The feature is in InvertedRadixTree, as opposed to RadixTree.
There is a (somewhat artificial) distinction between the RadixTree and the InvertedRadixTree. Both use the same data structure, but require quite different traversal algorithms.
The RadixTree is concerned with looking up keys stored in the tree given prefixes of those keys. The InvertedRadixTree is concerned with scanning input documents for keys contained in the tree (i.e. the other way around).
The traversal algorithm required to implement this feature was already implemented in InvertedRadixTree as it is needed by the existing getKeysContainedIn method. However it was not exposed directly because getKeysContainedIn wraps it in additional logic.
I have added InvertedRadixTree.getKeysPrefixing(CharSequence document) and related methods there.
There is a difference between this implementation and the exact functionality you were looking for, however it should be pretty efficient for your use case nonetheless. Basically the algorithm will traverse the tree and instead of returning the longest key, it will emit every key in the tree which it finds to prefix the input document. This functionality is basically free as the relevant nodes must be traversed anyway, and it might have additional applications beyond your use case. So for the longest key, just iterate through all keys returned and discard all but the last key. The last key will be the longest key in the tree which is a prefix of your input document (phone number in your case).
I tracked this in
issue 5 and you can find example usage there.
Thanks for the suggestion, and let me know if you have any problems.
Niall