Package com.google.api.generator.util
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 Summary
Constructors Constructor Description Trie()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> RdfsTraverseAndReduce(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.booleanhasPrefix(List<T> prefix)Returns true if some word in the trie begins with the given prefix.voidinsert(List<T> word)booleansearch(List<T> word)Returns true if the word is in the trie.
-
-
-
Method Detail
-
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. whenchris 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 uponbaseValue. Must handle the root node, i.e. whenchris 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.
-
-