Package org.naviqore.utils.search
Interface Trie<T>
- Type Parameters:
T- the type of the values that can be inserted into the Trie.
- All Known Implementing Classes:
CompressedTrie
public interface Trie<T>
Trie data structure for storing values with associated string keys, which supports inserting values and searching by
prefix. Duplicates are allowed, meaning multiple values can be associated with a single key.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiongetNodes()Retrieves all nodes currently in the Trie.voidInserts a value into the Trie associated with a specific key.intsize()Gets the number of unique keys in the Trie.startsWith(String prefix) Searches for all values associated with keys that start with the given prefix.
-
Method Details
-
insert
Inserts a value into the Trie associated with a specific key. If the key already exists, the value is added to the list of values for that key, allowing for duplicate values under the same key.- Parameters:
key- the key associated with the value to insert.value- the value to insert into the trie.
-
startsWith
Searches for all values associated with keys that start with the given prefix. If no values are found, returns an empty list.- Parameters:
prefix- the prefix of the key to search for.- Returns:
- a list of values whose keys start with the given prefix.
-
getNodes
Retrieves all nodes currently in the Trie.- Returns:
- a list of all nodes in the trie.
-
size
int size()Gets the number of unique keys in the Trie.- Returns:
- the number of unique keys stored in the trie.
-