Package com.google.api.generator.util
Class Trie<T>
java.lang.Object
com.google.api.generator.util.Trie<T>
A common-prefix trie. T represents the type of each "char" in a word (which is a T-typed list).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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.booleanReturns true if some word in the trie begins with the given prefix.voidbooleanReturns true if the word is in the trie.
-
Constructor Details
-
Trie
public Trie()
-
-
Method Details
-
insert
-
search
Returns true if the word is in the trie. -
hasPrefix
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.
-