Erdogan Seref
Erdogan Seref

Reputation: 11

How to implement common prefix search by using Apache Commons Trie?

Given a string, I want to return all strings in a trie that prefix the given string. So if a trie contains the strings "ae" and "b", trie.searchCommonPrefix('aeb') should return a list containing the string "ae" .

I don't want to write a custom Trie implementation so I tried to use the Trie data structure from the Apache Commons library.

Unfortunately, this only offers a method called prefixMap(K key) that returns a view of all elements prefixed by the key. This is the reverse function that I want.

How do we implement the common prefix search using the Trie data structure from the Apache Commons library?

I tried to use the prefixMap(K key) method to implement the common prefix search but I don't think this is not straightforward and not efficient.

Upvotes: 0

Views: 46

Answers (0)

Related Questions