Class Trie

java.lang.Object
com.palmergames.util.Trie

public class Trie extends Object
Dynamic trie structure that can add/remove keys and recursively get matching strings for a key
Author:
stzups
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    TrieNode implementation that handles any character and keeps track of its own children and character
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor that creates a new trie with a null root
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds and links new TrieNodes to the trie for each character in the string
    Gets all matching strings and their children for a key
    void
    Removes TrieNodes for a key

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Trie

      public Trie()
      Constructor that creates a new trie with a null root
  • Method Details

    • addKey

      public void addKey(String key)
      Adds and links new TrieNodes to the trie for each character in the string
      Parameters:
      key - key to add to trie, can be longer than one character
    • removeKey

      public void removeKey(String key)
      Removes TrieNodes for a key
      Parameters:
      key - key to remove
    • getStringsFromKey

      public List<String> getStringsFromKey(String key)
      Gets all matching strings and their children for a key
      Parameters:
      key - string to search for in tree
      Returns:
      matching strings and their children