public class TreeUtils extends Object
| Constructor and Description |
|---|
TreeUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> int |
childIndexOf(TreeOps2<T> ops,
T node) |
static <T> Map<T,com.google.common.collect.Multimap<T,T>> |
clusterNodesByFirstMultiaryAncestor(Tree<T> tree,
com.google.common.collect.Multimap<T,T> mapping)
Input: A mapping from cache nodes to candidate query nodes represented as a Multimap
|
static <T> long |
depth(Tree<T> tree) |
static <T> long |
depth(Tree<T> tree,
T node) |
static <A,B> com.google.common.collect.Multimap<A,B> |
deriveParentMapping(Tree<A> aTree,
Tree<B> bTree,
com.google.common.collect.Multimap<A,B> childMapping)
Given a mapping of child nodes, determine which parents may be mapped to each other.
|
static <T> T |
findAncestor(Tree<T> tree,
T node,
java.util.function.Predicate<T> predicate)
Find the first ancestor for which the predicate evaluates to true
|
static <T> T |
firstMultiaryAncestor(Tree<T> tree,
T node)
Return a node's first ancestor having an arity > 1
null if there is none.
|
static <T> T |
getFirstMultiaryAncestor(Tree<T> tree,
T node) |
static <T> void |
getLeafs(Collection<T> result,
Tree<T> tree,
T node) |
static <T> List<T> |
getLeafs(Tree<T> tree) |
static <T> Set<T> |
getParentsOf(Tree<T> tree,
Iterable<T> children)
Get the set of immediate parents for a given set of children
|
static <X> List<X> |
getUnaryAncestors(X x,
Tree<X> tree,
Tree<X> multiaryTree) |
static <T> com.google.common.collect.Multimap<T,T> |
groupByParent(Tree<T> tree,
Collection<T> nodes,
com.google.common.collect.Multimap<T,T> result) |
static <T> int |
indexOf(List<T> list,
T find,
java.util.function.BiPredicate<? super T,? super T> isEquiv) |
static <T> List<List<T>> |
innerNodesPerLevel(Tree<T> tree)
For each level, yield the inner nodes
The root node will always be part of the list, even if it does not have children
|
static <T> java.util.stream.Stream<T> |
inOrderSearch(T node,
java.util.function.Function<T,? extends Iterable<T>> parentToChildren) |
static <T,V> java.util.stream.Stream<Map.Entry<T,V>> |
inOrderSearch(T node,
java.util.function.Function<T,? extends Iterable<T>> parentToChildren,
java.util.function.Function<? super T,V> nodeToValue,
java.util.function.BiPredicate<T,V> doDescend)
In-order-search starting from the given node and descending into the tree.
|
static <T> java.util.stream.Stream<T> |
leafStream(Tree<T> tree) |
static <T> long |
nodeCount(Tree<T> tree) |
static <T> List<List<T>> |
nodesPerLevel(Tree<T> tree)
Returns the set of nodes in each level of the tree
The set containing the root will be the first item in the list
|
static <T> void |
parentMap(Map<T,T> result,
T parent,
java.util.function.Function<T,List<T>> parentToChildren) |
static <T> Map<T,T> |
parentMap(T root,
java.util.function.Function<T,List<T>> parentToChildren)
Traverse an op structure and create a map from each subOp to its immediate parent
NOTE It must be ensured that common sub expressions are different objects,
since we are using an identity hash map for mapping children to parents
|
static <T> Set<T> |
propagateBottomUpLabel(Tree<T> tree,
java.util.function.Predicate<T> predicate)
Given a predicate, return the minimum set of nodes, for which all nodes in their subtree satisfy the predicate.
|
static <T> Tree<T> |
remapSubTreesToLeafs(Tree<T> tree,
java.util.function.Function<? super T,? extends T> remapFn)
Create a new tree object which has certain nodes remapped with *leaf* nodes
|
static <T> Tree<T> |
removeUnaryNodes(Tree<T> tree) |
static <T> T |
removeUnaryNodes(Tree<T> tree,
T node,
com.google.common.collect.ListMultimap<T,T> parentToChildren) |
static <T> Tree<T> |
replace(Tree<T> tree,
T node,
T replacement) |
static <T> T |
replaceNode(Tree<T> tree,
T node,
T replacement,
java.util.function.BiPredicate<? super T,? super T> isEquiv) |
static <T> T |
substitute(T node,
boolean descendIntoSubst,
java.util.function.Function<? super T,? extends Collection<? extends T>> getChildrenFn,
java.util.function.Function<? super T,? extends T> transformFn,
java.util.function.BiFunction<T,List<T>,T> copyFn) |
static <T> T |
substitute(T node,
boolean descendIntoSubst,
TreeOps2<T> ops,
java.util.function.Function<? super T,? extends T> transformFn) |
static <T> Tree<T> |
subTree(Tree<T> tree,
T newRoot) |
public static <T> com.google.common.collect.Multimap<T,T> groupByParent(Tree<T> tree, Collection<T> nodes, com.google.common.collect.Multimap<T,T> result)
public static <T> Set<T> propagateBottomUpLabel(Tree<T> tree, java.util.function.Predicate<T> predicate)
tree - predicate - public static <T> long nodeCount(Tree<T> tree)
public static <T> long depth(Tree<T> tree)
public static <T> long depth(Tree<T> tree, T node)
public static <T> int childIndexOf(TreeOps2<T> ops, T node)
public static <T> int indexOf(List<T> list, T find, java.util.function.BiPredicate<? super T,? super T> isEquiv)
public static <T> T replaceNode(Tree<T> tree, T node, T replacement, java.util.function.BiPredicate<? super T,? super T> isEquiv)
public static <T> T substitute(T node,
boolean descendIntoSubst,
TreeOps2<T> ops,
java.util.function.Function<? super T,? extends T> transformFn)
public static <T> T substitute(T node,
boolean descendIntoSubst,
java.util.function.Function<? super T,? extends Collection<? extends T>> getChildrenFn,
java.util.function.Function<? super T,? extends T> transformFn,
java.util.function.BiFunction<T,List<T>,T> copyFn)
public static <T> T findAncestor(Tree<T> tree, T node, java.util.function.Predicate<T> predicate)
tree - node - predicate - public static <T> java.util.stream.Stream<T> inOrderSearch(T node, java.util.function.Function<T,? extends Iterable<T>> parentToChildren)
public static <T,V> java.util.stream.Stream<Map.Entry<T,V>> inOrderSearch(T node, java.util.function.Function<T,? extends Iterable<T>> parentToChildren, java.util.function.Function<? super T,V> nodeToValue, java.util.function.BiPredicate<T,V> doDescend)
node - parentToChildren - nodeToValue - doDescend - public static <T> List<List<T>> innerNodesPerLevel(Tree<T> tree)
public static <T> List<List<T>> nodesPerLevel(Tree<T> tree)
tree - public static <T> java.util.stream.Stream<T> leafStream(Tree<T> tree)
public static <T> void getLeafs(Collection<T> result, Tree<T> tree, T node)
public static <T> Set<T> getParentsOf(Tree<T> tree, Iterable<T> children)
tree - children - public static <T> Map<T,T> parentMap(T root, java.util.function.Function<T,List<T>> parentToChildren)
op - public static <T> void parentMap(Map<T,T> result, T parent, java.util.function.Function<T,List<T>> parentToChildren)
public static <T> Tree<T> remapSubTreesToLeafs(Tree<T> tree, java.util.function.Function<? super T,? extends T> remapFn)
tree - remapFn - public static <T> T removeUnaryNodes(Tree<T> tree, T node, com.google.common.collect.ListMultimap<T,T> parentToChildren)
public static <T> Map<T,com.google.common.collect.Multimap<T,T>> clusterNodesByFirstMultiaryAncestor(Tree<T> tree, com.google.common.collect.Multimap<T,T> mapping)
cacheTree - tree - cacheToQueryCands - public static <T> T getFirstMultiaryAncestor(Tree<T> tree, T node)
public static <T> T firstMultiaryAncestor(Tree<T> tree, T node)
tree - node - public static <X> List<X> getUnaryAncestors(X x, Tree<X> tree, Tree<X> multiaryTree)
public static <A,B> com.google.common.collect.Multimap<A,B> deriveParentMapping(Tree<A> aTree, Tree<B> bTree, com.google.common.collect.Multimap<A,B> childMapping)
aTree - bTree - childMapping - Copyright © 2018. All rights reserved.