List of usage examples for com.google.common.graph Traverser forTree
public static <N> Traverser<N> forTree(SuccessorsFunction<N> tree)
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()); }