Class CompressedTrie<T>

java.lang.Object
org.naviqore.utils.search.CompressedTrie<T>
All Implemented Interfaces:
Trie<T>

public class CompressedTrie<T> extends Object implements Trie<T>
A trie data structure that compresses the edges. It allows for efficient storage and retrieval of strings and their associated values.
  • Constructor Details

    • CompressedTrie

      public CompressedTrie()
  • Method Details

    • insert

      public void insert(String key, T value)
      Description copied from interface: Trie
      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.
      Specified by:
      insert in interface Trie<T>
      Parameters:
      key - the key associated with the value to insert.
      value - the value to insert into the trie.
    • startsWith

      public List<T> startsWith(String prefix)
      Description copied from interface: Trie
      Searches for all values associated with keys that start with the given prefix. If no values are found, returns an empty list.
      Specified by:
      startsWith in interface Trie<T>
      Parameters:
      prefix - the prefix of the key to search for.
      Returns:
      a list of values whose keys start with the given prefix.
    • getNodes

      public List<Trie.Node<T>> getNodes()
      Description copied from interface: Trie
      Retrieves all nodes currently in the Trie.
      Specified by:
      getNodes in interface Trie<T>
      Returns:
      a list of all nodes in the trie.
    • size

      public int size()
      Description copied from interface: Trie
      Gets the number of unique keys in the Trie.
      Specified by:
      size in interface Trie<T>
      Returns:
      the number of unique keys stored in the trie.
    • trimToSize

      public void trimToSize()
      Reduces the memory footprint by trimming the capacity of node internal data structures.