X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=bd728af5d665e695733364fc0783436b4f072ea2;hb=5db16dd3e0bf609bc0fa84ee7d067f6bbc58013e;hp=99d03954a55e94fbbae1d7bfebc0dd5bca488e28;hpb=79d19dd14db25dd04e9fc9e0137ce9e8c6e4744f;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index 99d0395..bd728af 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -357,7 +357,9 @@ bool XMLTree::IsChild(treeNode x, treeNode y) if (!is_ancestor(Par, x, y)) return false; return depth(Par, x) == (depth(Par, y) + 1); } - +bool XMLTree::IsFirstChild(treeNode x){ + return ((x != NULLT)&&(x==Root() || prev_sibling(Par,x) == NULLT)); +} // NumChildren(x): number of children of node x. Constant time with the data structure // of Sadakane. int XMLTree::NumChildren(treeNode x) @@ -499,6 +501,14 @@ treeNode XMLTree::FirstChild(treeNode x) return first_child(Par, x); } +treeNode XMLTree::LastChild(treeNode x) +{ + if (x == Root() || isleaf(Par,x) || x == NULLT) + return x; + else + return find_open(Par,find_close(Par,parent(Par,x))-1); +} + // NextSibling(x): returns the next sibling of node x, assuming it exists. treeNode XMLTree::NextSibling(treeNode x) { @@ -556,13 +566,14 @@ treeNode XMLTree::TaggedDesc(treeNode x, TagType tag) exit(1); } - int r, s; + //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); + int s = (int) Tags->select_next(tag,node2tagpos(x)); + /*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 if (!is_ancestor(Par, x, y)) return NULLT; // the next node tagged tag (in preorder) is not within the subtree of x. @@ -649,14 +660,15 @@ treeNode XMLTree::TaggedDescOrFollOnly(treeNode x,TagType *folltags, unsigned in { treeNode res,y,lim; - int r,s; + //int r,s; lim = find_close(Par,root); res=NULLT; for (unsigned int i = 0; i < ftlen; i ++ ) { - r = (int) Tags->rank(folltags[i], node2tagpos(x)); - s = (int) Tags->select(folltags[i], r+1); + int s = (int) Tags->select_next(folltags[i],node2tagpos(x)); + /*r = (int) Tags->rank(folltags[i], node2tagpos(x)); + s = (int) Tags->select(folltags[i], r+1);*/ if (s == -1) y = NULLT; // there is no such node else { @@ -752,12 +764,13 @@ treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) exit(1); } - int r, s; + //int r, s; if (x ==NULLT || x == Root()) return NULLT; - - r = (int) Tags->rank(tag, find_close(Par, x)); - s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag. + + int s = (int) Tags->select_next(tag,find_close(Par,x)); + /*r = (int) Tags->rank(tag, find_close(Par, x)); + 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; else return tagpos2node(s); } @@ -767,17 +780,15 @@ treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) treeNode XMLTree::TaggedFollBelow(treeNode x, TagType tag, treeNode root) { - int r, s; - int lim = node2tagpos(find_close(Par,root)); - if (x ==NULLT || x == Root()) - return NULLT; - - r = (int) Tags->rank(tag,find_close(Par,x)); - s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag. - if (s==-1 || s >= lim) - return NULLT; - else - return tagpos2node(s); + if (x == NULLT || x == Root()) return NULLT; + treeNode s = (treeNode) Tags->select_next(tag,find_close(Par,x)); + /*int r = (int) Tags->rank(tag, find_close(Par, x)); + int s = (int) Tags->select(tag, r+1); */ + if (root == Root()) + return s; + + if (s == NULLT || s >= find_close(Par,root)) return NULLT; + return s; } @@ -790,14 +801,15 @@ treeNode XMLTree::TaggedFollowingSibling(treeNode x, TagType tag) exit(1); } - int r, s; + //int r, s; treeNode ns = next_sibling(Par,x); if (x == NULLT || x == Root() || ns == -1) return NULLT; - r = (int) Tags->rank(tag, node2tagpos(ns)-1); - s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag. + int s = (int) Tags->select_next(tag,node2tagpos(ns)-1); + /*r = (int) Tags->rank(tag, node2tagpos(ns)-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; else return tagpos2node(s); }