X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=4ddec0170a5186dc02c43e98ab59e525c89380c2;hb=dd9992dcd5366f37820c24ed7cddf24ecbc0d549;hp=bb861a9765e31a34e4114013c26abbeb093b987f;hpb=0f2d33d4ee4291d61750769c2918263c7e485ffa;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index bb861a9..4ddec01 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -268,6 +268,9 @@ int XMLTree::SubtreeTags(treeNode x, TagType tag) fprintf(stderr, "Error: data structure has not been constructed properly\n"); exit(1); } + if (x == Root()) + x = first_child(Par,x); + int s = x + 2*subtree_size(Par, x) - 1; @@ -368,7 +371,7 @@ TagType XMLTree::Tag(treeNode x) fprintf(stderr, "Error: data structure has not been constructed properly\n"); exit(1); } - + return Tags->access(node2tagpos(x)); } @@ -496,6 +499,9 @@ treeNode XMLTree::TaggedDesc(treeNode x, TagType tag) int r, s; treeNode y; + if (isleaf(Par,x)) + return NULLT; + r = (int) Tags->rank(tag, node2tagpos(x)); s = (int) Tags->select(tag, r+1); if (s == -1) return NULLT; // there is no such node @@ -504,6 +510,28 @@ treeNode XMLTree::TaggedDesc(treeNode x, TagType tag) else return y; } +// TaggedNext(x,tag): returns the first node tagged tag with larger preorder than x +// Returns NULLT if there is none. +treeNode XMLTree::TaggedNext(treeNode x, TagType tag) + { + if (!finished) { + fprintf(stderr, "Error: data structure has not been constructed properly\n"); + exit(1); + } + + int r, s; + treeNode y; + if (x==NULLT) + return NULLT; + + r = (int) Tags->rank(tag, node2tagpos(x)); + s = (int) Tags->select(tag, r+1); + if (s == -1) return NULLT; // there is no such node + y = tagpos2node(s); // transforms the tag position into a node position + return (y<=x ? NULLT : y); + } + + // TaggedPrec(x,tag): returns the first node tagged tag with smaller preorder than x and not an // ancestor of x. Returns NULLT if there is none. treeNode XMLTree::TaggedPrec(treeNode x, TagType tag) @@ -539,9 +567,9 @@ treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) } int r, s; - if (x == Root() || (next_sibling(Par,x) == -1 )) + if (x ==NULLT || x == Root()|| (next_sibling(Par,x) == -1 )) return NULLT; - + r = (int) Tags->rank(tag, node2tagpos(next_sibling(Par, x))-1); s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag. if (s==-1) return NULLT;