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
    Modifier and Type
    Interface
    Description
    static interface 
    Node within the Trie structure, containing a list of children and values.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves all nodes currently in the Trie.
    void
    insert(String key, T value)
    Inserts a value into the Trie associated with a specific key.
    int
    Gets the number of unique keys in the Trie.
    Searches for all values associated with keys that start with the given prefix.
  • Method Details

    • insert

      void insert(String key, T value)
      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

      List<T> startsWith(String prefix)
      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

      List<Trie.Node<T>> 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.