/** * Rewrite expression tree to update the leaves. * @param root the root of the tree to fix * @param leafReorder a map from old leaf ids to new leaf ids * @return the fixed root */ static ExpressionTree rewriteLeaves(ExpressionTree root, int[] leafReorder) { // The leaves could be shared in the tree. Use Set to remove the duplicates. Set<ExpressionTree> leaves = new HashSet<ExpressionTree>(); Queue<ExpressionTree> nodes = new LinkedList<ExpressionTree>(); nodes.add(root); while(!nodes.isEmpty()) { ExpressionTree node = nodes.remove(); if (node.getOperator() == ExpressionTree.Operator.LEAF) { leaves.add(node); } else { if (node.getChildren() != null){ nodes.addAll(node.getChildren()); } } } // Update the leaf in place for(ExpressionTree leaf : leaves) { leaf.setLeaf(leafReorder[leaf.getLeaf()]); } return root; }
/** * Recursively explore the tree to find the leaves that are still reachable * after optimizations. * @param tree the node to check next * @param next the next available leaf id * @param leafReorder * @return the next available leaf id */ static int compactLeaves(ExpressionTree tree, int next, int[] leafReorder) { if (tree.getOperator() == ExpressionTree.Operator.LEAF) { int oldLeaf = tree.getLeaf(); if (leafReorder[oldLeaf] == -1) { leafReorder[oldLeaf] = next++; } } else if (tree.getChildren() != null){ for(ExpressionTree child: tree.getChildren()) { next = compactLeaves(child, next, leafReorder); } } return next; }
PredicateLeaf l = leaves.get(expr.getLeaf()); if (!addLiteral(literals, l)) { return; PredicateLeaf l = leaves.get(subExpr.getLeaf()); if (bucketLeaves.contains(l)) { if (!addLiteral(literals, l)) { return; PredicateLeaf l = leaves.get(subExpr.getLeaf()); if (bucketLeaves.contains(l)) { if (!addLiteral(literals, l)) {
PredicateLeaf l = leaves.get(expr.getLeaf()); if (!addLiteral(literals, l)) { return; PredicateLeaf l = leaves.get(subExpr.getLeaf()); if (bucketLeaves.contains(l)) { if (!addLiteral(literals, l)) { return; PredicateLeaf l = leaves.get(subExpr.getLeaf()); if (bucketLeaves.contains(l)) { if (!addLiteral(literals, l)) {
PredicateLeaf leaf = leaves.get(root.getLeaf());
PredicateLeaf leaf = leaves.get(root.getLeaf());
/** * Rewrite expression tree to update the leaves. * @param root the root of the tree to fix * @param leafReorder a map from old leaf ids to new leaf ids * @return the fixed root */ static ExpressionTree rewriteLeaves(ExpressionTree root, int[] leafReorder) { // The leaves could be shared in the tree. Use Set to remove the duplicates. Set<ExpressionTree> leaves = new HashSet<ExpressionTree>(); Queue<ExpressionTree> nodes = new LinkedList<ExpressionTree>(); nodes.add(root); while(!nodes.isEmpty()) { ExpressionTree node = nodes.remove(); if (node.getOperator() == ExpressionTree.Operator.LEAF) { leaves.add(node); } else { if (node.getChildren() != null){ nodes.addAll(node.getChildren()); } } } // Update the leaf in place for(ExpressionTree leaf : leaves) { leaf.setLeaf(leafReorder[leaf.getLeaf()]); } return root; }
/** * Recursively explore the tree to find the leaves that are still reachable * after optimizations. * @param tree the node to check next * @param next the next available leaf id * @param leafReorder * @return the next available leaf id */ static int compactLeaves(ExpressionTree tree, int next, int[] leafReorder) { if (tree.getOperator() == ExpressionTree.Operator.LEAF) { int oldLeaf = tree.getLeaf(); if (leafReorder[oldLeaf] == -1) { leafReorder[oldLeaf] = next++; } } else if (tree.getChildren() != null){ for(ExpressionTree child: tree.getChildren()) { next = compactLeaves(child, next, leafReorder); } } return next; }