- child = first_child(Par, x); // starts at first child of node x\r
- if (child==(treeNode)-1) return NULLT; // node x is a leaf, there is no such child\r
- while (child!=(treeNode)-1) {\r
- if (Tags->access(node2tagpos(child)) == tag) { // current child is labeled with tag of interest\r
- i--;\r
- if (i==0) return child; // we have seen i children of x tagged tag, this is the one we are looking for\r
- }\r
- child = next_sibling(Par, x); // OK, let's try with the next child\r
- }\r
- return NULLT; // no such child was found \r
+ NULLT_IF(x==NULLT || isleaf(Par,x));\r
+\r
+ treeNode child; \r
+ child = first_child(Par, x); // starts at first child of node x\r
+ if (get_field(tags_fix,tags_blen,node2tagpos(child)) == tag)\r
+ return child;\r
+ else\r
+ return TaggedFollSibling(child,tag);\r
+ }\r
+\r
+// TaggedSibling(x,tag): returns the first sibling of node x tagged tag, or NULLT if there is none.\r
+treeNode XMLTree::TaggedFollSibling(treeNode x, TagType tag)\r
+{\r
+ NULLT_IF(x==NULLT);\r
+ treeNode sibling = next_sibling(Par, x); \r
+ while (sibling != NULLT) {\r
+ if (get_field(tags_fix,tags_blen,node2tagpos(sibling)) == tag) // current sibling is labeled with tag of interest\r
+ return sibling; \r
+ sibling = next_sibling(Par, sibling); // OK, let's try with the next sibling\r
+ }\r
+ return NULLT; // no such sibling was found \r
+}\r
+\r
+treeNode XMLTree::SelectChild(treeNode x, std::unordered_set<int> *tags)\r
+{\r
+ \r
+ NULLT_IF(x==NULLT || isleaf(Par,x));\r
+ int i;\r
+ treeNode child = first_child(Par, x); \r
+ TagType t = get_field(tags_fix, tags_blen, node2tagpos(child));\r
+ std::unordered_set<int>::const_iterator tagit = tags->find(t);\r
+ if (tagit != tags->end()) return child; \r
+ return SelectFollSibling(child,tags);\r
+}\r
+\r
+\r
+treeNode XMLTree::SelectFollSibling(treeNode x, std::unordered_set<int> *tags)\r
+{\r
+\r
+ NULLT_IF(x==NULLT);\r
+ int i;\r
+ TagType t;\r
+ treeNode sibling = next_sibling(Par, x);\r
+ std::unordered_set<int>::const_iterator tagit;\r
+ while (sibling != NULLT) {\r
+ t = get_field(tags_fix, tags_blen, node2tagpos(sibling));\r
+ tagit = tags->find(t);\r
+ if (tagit != tags->end()) return sibling;\r
+ sibling = next_sibling(Par, sibling);\r
+ }\r
+ return NULLT; \r