All Known Subinterfaces:
SuffixTrie
All Known Implementing Classes:
PrefixTrieImpl, ReversePrefixTrie

public interface PrefixTrie
The PrefixTrie can perform fast prefix matching. By traversing the trie based on the characters in the prefix being searched, it is possible to find all strings in the Trie that have the given prefix.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The number of complete words in this trie.
    boolean
    contains(String string)
    Checks if a word exists in this trie.
    boolean
    delete(String string)
    Deletes a word from the trie.
    boolean
    insert(String string)
    Inserts a word into the trie.
    boolean
    isPrefix(String prefix)
    Checks if prefix is present in this trie.
    A detailed string representation of the structure of this trie.
    int
    The number of nodes in this trie.
    startsWith(String prefix, int limit)
    Try to find strings which start with prefix.
  • Method Details

    • startsWith

      Collection<String> startsWith(String prefix, int limit)
      Try to find strings which start with prefix. Matching strings are always in lexicographical order.
      Parameters:
      prefix - to look for
      limit - maximum number of found strings
      Returns:
      collection of words with the same prefix
    • contains

      boolean contains(String string)
      Checks if a word exists in this trie.
      Parameters:
      string - to check
      Returns:
      true if word is in this trie
    • isPrefix

      boolean isPrefix(String prefix)
      Checks if prefix is present in this trie.
      Parameters:
      prefix - to check
      Returns:
      true if prefix exists
    • insert

      boolean insert(String string)
      Inserts a word into the trie. Duplicate words will be ignored.
      Parameters:
      string - word to be inserted
      Returns:
      true if the word was inserted false if it already existed
    • delete

      boolean delete(String string)
      Deletes a word from the trie. The number of complete words will be decremented by one and the size of the trie will shrink by the number of unique characters and their placements in the deleted word if they aren't used by a different word.
      Parameters:
      string - to be deleted
      Returns:
      true if word is successfully deleted false if word was not in the trie
    • size

      int size()
      The number of nodes in this trie.
      Returns:
      number of nodes
    • completeWords

      int completeWords()
      The number of complete words in this trie.
      Returns:
      number of complete words
    • prettyString

      String prettyString()
      A detailed string representation of the structure of this trie.
      Returns:
      detailed string