Class Trie<T>

java.lang.Object
com.google.api.generator.util.Trie<T>

public class Trie<T> extends Object
A common-prefix trie. T represents the type of each "char" in a word (which is a T-typed list).
  • Constructor Details

    • Trie

      public Trie()
  • Method Details

    • insert

      public void insert(List<T> word)
    • search

      public boolean search(List<T> word)
      Returns true if the word is in the trie.
    • hasPrefix

      public boolean hasPrefix(List<T> prefix)
      Returns true if some word in the trie begins with the given prefix.
    • dfsTraverseAndReduce

      public <R> R dfsTraverseAndReduce(Function<T,R> parentPreprocFn, TriFunction<T,R,R,R> parentPostprocFn, BiFunction<T,R,R> leafReduceFn, R baseValue)
      Reduces the trie to a single value, via a DFS traversal.
      Parameters:
      parentPreprocFn - Transforms a parent node into an R-typed base value for consumption by the child nodes. The rest of the children will compute their values using this as a base as well, so it accumulates computational results as the traversal progresses. Does not handle the root node (i.e. when chr is null).
      leafReduceFn - Transforms a child node into an R-typed value using the value computed by the parent nodes' preprocessing functions.
      parentPostprocFn - Transforms the post-traversal result (from the child nodes) into R-typed values, further building upon baseValue. Must handle the root node, i.e. when chr is null.
      baseValue - The base value upon which subsequent reductions will be performed. Ensure this is a type that can accumulate values, such as StringBuilder. An immutable type such as String will not work here.