/** * Print the subtree rooted at node *top to the output stream * @param out the output stream * @param prefix the number of spaces ' ' in front of each node * @param top the current tree sub root */ public string printSubTree(int prefix, SafraTreeNode top) { string returnString = ""; for (int i = 0; i < prefix; i++) { returnString += " "; } returnString += top.ToString() + "\r\n"; //for (SafraTreeNode::child_iterator it=top->children_begin(); // it!=top->children_end(); // ++it) { // printSubTree(out, prefix+1, *it); //} SafraTreeNode it = top.children_begin(); while (it != top.children_end()) { printSubTree(prefix + 1, it); it = it.increment(); } return(returnString); }
/** Node visitor */ public void visit(SafraTree tree, SafraTreeNode node) { if (node.getChildCount() == 0) { return; } BitSet labeling_union = new BitSet(); //for (SafraTreeNode::child_iterator it=node->children_begin();it!=node->children_end();++it) SafraTreeNode it = node.children_begin(); while (it != node.children_end()) { labeling_union.Union(it.getLabeling()); it = it.increment(); } if (labeling_union == node.getLabeling()) { // The union of the labelings of the children is exactly the // same as the labeling of the parent -> // remove children STVisitor_remove_subtree stv_remove = new STVisitor_remove_subtree(_tree_template); tree.walkChildrenPostOrder(stv_remove, node); node.setFinalFlag(true);///////////should be "+ i", means in Li } }
/** Node visitor */ public void visit(SafraTree tree, SafraTreeNode node) { if (node.getChildCount() <= 1) { return; } BitSet already_seen = new BitSet(); bool first = true; //for (SafraTreeNode::child_iterator it=node->children_begin();it!=node->children_end();++it) SafraTreeNode it = node.children_begin(); while (it != node.children_end()) { SafraTreeNode cur_child = it; if (first) { already_seen = new BitSet(cur_child.getLabeling()); ////////////get the NBA states in child first = false; it = it.increment(); ////////note added } else { BitSet current = new BitSet(cur_child.getLabeling()); BitSet intersection = new BitSet(already_seen); // make copy if (intersection.intersects(current)) { // There are some labels, which occur in older brothers, // remove them from current node and its children STVisitor_subtract_labeling stv_sub = new STVisitor_subtract_labeling(intersection); tree.walkSubTreePostOrder(stv_sub, cur_child); } already_seen.Union(current); it = it.increment(); } } }
/** Node visitor */ public void visit(SafraTree tree, SafraTreeNode node) { if (node.getChildCount() <= 1) { return; } BitSet already_seen = new BitSet(); bool first = true; //for (SafraTreeNode::child_iterator it=node->children_begin();it!=node->children_end();++it) SafraTreeNode it = node.children_begin(); while (it != node.children_end()) { SafraTreeNode cur_child = it; if (first) { already_seen = new BitSet(cur_child.getLabeling());////////////get the NBA states in child first = false; it = it.increment();////////note added } else { BitSet current = new BitSet(cur_child.getLabeling()); BitSet intersection = new BitSet(already_seen); // make copy if (intersection.intersects(current)) { // There are some labels, which occur in older brothers, // remove them from current node and its children STVisitor_subtract_labeling stv_sub = new STVisitor_subtract_labeling(intersection); tree.walkSubTreePostOrder(stv_sub, cur_child); } already_seen.Union(current); it = it.increment(); } } }
/** * Copy the subtree (the children) of *other * to *top, becoming the children of *top */ public void copySubTree(SafraTreeNode top, SafraTreeNode other) { if (other == null) { return; } //for (SafraTreeNode::child_iterator it=other->children_begin();it!=other->children_end();++it) { // SafraTreeNode *n=_nodes[(*it)->getID()], *n_o=*it; // top->addAsYoungestChild(n); // copySubTree(n, n_o); //} SafraTreeNode it = other.children_begin(); while (it != other.children_end()) { SafraTreeNode n = _nodes[it.getID()]; top.addAsYoungestChild(n); copySubTree(n, it); it = it.increment(); } }
/** Node visitor */ public void visit(SafraTree tree, SafraTreeNode node) { if (node.getChildCount() <= 1) { return; } int i = 0; //for (SafraTreeNode::child_iterator it= node->children_begin(); it!=node->children_end();++it) SafraTreeNode it = node.children_begin(); while (it != node.children_end()) { BitSet reachable_this = _node_reachability[it.getID()]; reachable_this.clear(); _node_order[it.getID()] = i++; BitSet label_this = it.getLabeling(); //for (BitSetIterator label_it(label_this); label_it != BitSetIterator::end(label_this); ++label_it) for (int label_it = 0; label_it < label_this.Count; label_it++) { reachable_this.Union(_nba_reachability[label_it]); } // std::cerr << "reachability_this: "<<reachable_this << std::endl; it = it.increment(); } // reorder... // std::cerr << "Sorting!" << std::endl; // Bubble sort, ough! bool finished = false; while (!finished) { finished = true; for (SafraTreeNode a = node.getOldestChild(); a != null && a.getYoungerBrother() != null; a = a.getYoungerBrother()) { SafraTreeNode b = a.getYoungerBrother(); BitSet reach_a = _node_reachability[a.getID()]; BitSet reach_b = _node_reachability[b.getID()]; if (reach_a.intersects(reach_b)) { // a and b are not independant... // --> keep relative order... System.Diagnostics.Debug.Assert(_node_order[a.getID()] < _node_order[b.getID()]); } else { // a and b are independant... if (!(a.getLabeling() < b.getLabeling())) { // swap node.swapChildren(a, b); a = b; finished = false; } } } } }
/** * Print the subtree rooted at node *top to the output stream * @param out the output stream * @param prefix the number of spaces ' ' in front of each node * @param top the current tree sub root */ public string printSubTree(int prefix, SafraTreeNode top) { string returnString = ""; for (int i = 0; i < prefix; i++) { returnString += " "; } returnString += top.ToString() + "\r\n"; //for (SafraTreeNode::child_iterator it=top->children_begin(); // it!=top->children_end(); // ++it) { // printSubTree(out, prefix+1, *it); //} SafraTreeNode it = top.children_begin(); while (it != top.children_end()) { printSubTree(prefix + 1, it); it = it.increment(); } return returnString; }