Example usage for com.google.common.graph Traverser forTree

List of usage examples for com.google.common.graph Traverser forTree

Introduction

In this page you can find the example usage for com.google.common.graph Traverser forTree.

Prototype

public static <N> Traverser<N> forTree(SuccessorsFunction<N> tree) 

Source Link

Document

Creates a new traverser for a directed acyclic graph that has at most one path from the start node(s) to any node reachable from the start node(s), and has no paths from any start node to any other start node, such as a tree or forest.

Usage

From source file:io.prestosql.sql.util.AstUtils.java

public static Stream<Node> preOrder(Node node) {
    return stream(Traverser.forTree((SuccessorsFunction<Node>) Node::getChildren)
            .depthFirstPreOrder(requireNonNull(node, "node is null")));
}

From source file:io.prestosql.cost.StatsAndCosts.java

public static StatsAndCosts create(PlanNode root, StatsProvider statsProvider, CostProvider costProvider) {
    Iterable<PlanNode> planIterator = Traverser.forTree(PlanNode::getSources).depthFirstPreOrder(root);
    ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> stats = ImmutableMap.builder();
    ImmutableMap.Builder<PlanNodeId, PlanNodeCostEstimate> costs = ImmutableMap.builder();
    for (PlanNode node : planIterator) {
        stats.put(node.getId(), statsProvider.getStats(node));
        costs.put(node.getId(), costProvider.getCumulativeCost(node));
    }//  w  ww. j av a2  s.  c  o m
    return new StatsAndCosts(stats.build(), costs.build());
}

From source file:io.prestosql.cost.StatsAndCosts.java

public StatsAndCosts getForSubplan(PlanNode root) {
    Iterable<PlanNode> planIterator = Traverser.forTree(PlanNode::getSources).depthFirstPreOrder(root);
    ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> filteredStats = ImmutableMap.builder();
    ImmutableMap.Builder<PlanNodeId, PlanNodeCostEstimate> filteredCosts = ImmutableMap.builder();
    for (PlanNode node : planIterator) {
        if (stats.containsKey(node.getId())) {
            filteredStats.put(node.getId(), stats.get(node.getId()));
        }/*from  ww w .  j av a  2s .  c  o  m*/
        if (costs.containsKey(node.getId())) {
            filteredCosts.put(node.getId(), costs.get(node.getId()));
        }
    }
    return new StatsAndCosts(filteredStats.build(), filteredCosts.build());
}