public class Trie<T> extends Object
| Constructor and Description |
|---|
Trie() |
| Modifier and Type | Method and Description |
|---|---|
<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.
|
boolean |
hasPrefix(List<T> prefix)
Returns true if some word in the trie begins with the given prefix.
|
void |
insert(List<T> word) |
boolean |
search(List<T> word)
Returns true if the word is in the trie.
|
public boolean hasPrefix(List<T> prefix)
public <R> R dfsTraverseAndReduce(Function<T,R> parentPreprocFn, TriFunction<T,R,R,R> parentPostprocFn, BiFunction<T,R,R> leafReduceFn, R baseValue)
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.Copyright © 2022 Google LLC. All rights reserved.