X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=a0815b861448216527aaa5630ab59970bd3a3e23;hb=45de465016fdd58a01d69012691772ef1b8d335c;hp=764e9101dfabf2e1aad914ad1022b2075b50ac79;hpb=f21a49f63aa3813e0b0b972bf81dc752b2a37153;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index 764e910..a0815b8 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -13,11 +13,6 @@ using std::string; // Current implementation corresponds to balanced-parentheses representation for // the tree, and storing 2 tags per tree node (opening and closing tags). -// tag position -> tree node -static treeNode tagpos2node(int t) - { - return (treeNode) t; - } static int bits8 (int t ) { int r = bits(t); @@ -29,36 +24,7 @@ static int bits8 (int t ) { return r; } -// tree node -> tag position -static int node2tagpos(treeNode x) -{ - return (int)x; -} - -static int fast_find_close(bp *b,int s) -{ - return fwd_excess(b,s,-1); -} - -static int fast_inspect(bp* Par,treeNode i) -{ - int j,l; - j = i >> logD; - l = i & (D-1); - return (Par->B[j] >> (D-1-l)) & 1; -} - -static treeNode fast_first_child(bp *Par, treeNode x) -{ - x = x+1; - return (fast_inspect(Par,x) == OP) ? x : NULLT; -} -static treeNode fast_next_sibling(bp* Par,treeNode x) -{ - x = fast_find_close(Par,x)+1; - return (fast_inspect(Par,x) == OP) ? x : NULLT; -} static treeNode fast_sibling(bp* Par,treeNode x,TagType tag){ @@ -98,12 +64,7 @@ static uint fast_get_field(uint* A,int len, int idx) } -inline bool fast_is_ancestor(bp * Par,treeNode x,treeNode y){ - if (x > y) - return false; - else - return (x==0) || (y <= fast_find_close(Par,x)); -} + XMLTree::XMLTree( pb * const par, uint npar, vector * const TN, TagIdMap * const tim, @@ -410,11 +371,11 @@ bool XMLTree::IsChild(treeNode x, treeNode y) } // IsFirstChild(x): returns whether node x is the first child of its parent. -bool XMLTree::IsFirstChild(treeNode x) +/*bool XMLTree::IsFirstChild(treeNode x) { return ((x != NULLT)&&(x==Root() || prev_sibling(Par,x) == (treeNode)-1)); } - +*/ // NumChildren(x): number of children of node x. Constant time with the data structure // of Sadakane. @@ -479,14 +440,14 @@ range XMLTree::DocIds(treeNode x) } // Parent(x): returns the parent node of node x. - +/* treeNode XMLTree::Parent(treeNode x) { if (x == Root()) return NULLT; else return parent(Par, x);; - } + }*/ // Child(x,i): returns the i-th child of node x, assuming it exists. treeNode XMLTree::Child(treeNode x, int i) @@ -496,13 +457,14 @@ treeNode XMLTree::Child(treeNode x, int i) } // FirstChild(x): returns the first child of node x, assuming it exists. Very fast in BP. - +/* treeNode XMLTree::FirstChild(treeNode x) { NULLT_IF(x==NULLT); return fast_first_child(Par, x); } - +*/ +/* treeNode XMLTree::FirstElement(treeNode x) { NULLT_IF(x==NULLT); @@ -525,7 +487,7 @@ treeNode XMLTree::FirstElement(treeNode x) return x; } } - +*//* treeNode XMLTree::NextElement(treeNode x) { NULLT_IF(x==NULLT); @@ -536,7 +498,7 @@ treeNode XMLTree::NextElement(treeNode x) return (fast_inspect(Par,x)==OP)? x : NULLT; } else return x; -} + }*/ // LastChild(x): returns the last child of node x. treeNode XMLTree::LastChild(treeNode x) @@ -546,13 +508,13 @@ treeNode XMLTree::LastChild(treeNode x) } // NextSibling(x): returns the next sibling of node x, assuming it exists. -treeNode XMLTree::NextSibling(treeNode x) +/*treeNode XMLTree::NextSibling(treeNode x) { NULLT_IF(x==NULLT || x == Root() ); x = fast_find_close(Par,x)+1; return (fast_inspect(Par,x) == CP ? NULLT : x); } - +*/ // PrevSibling(x): returns the previous sibling of node x, assuming it exists. treeNode XMLTree::PrevSibling(treeNode x) @@ -625,6 +587,7 @@ treeNode XMLTree::SelectFollowingSibling(treeNode x, TagIdSet *tags) // TaggedDescendant(x,tag): returns the first node tagged tag with larger preorder than x and within // the subtree of x. Returns NULLT if there is none. +/* treeNode XMLTree::TaggedDescendant(treeNode x, TagType tag) { //NULLT_IF(x==NULLT || fast_isleaf(Par,x)); @@ -636,7 +599,7 @@ treeNode XMLTree::TaggedDescendant(treeNode x, TagType tag) return (fast_is_ancestor(Par,x,y) ? y : NULLT); } - +*/ treeNode XMLTree::SelectDescendant(treeNode x, TagIdSet *tags) { @@ -689,35 +652,19 @@ treeNode XMLTree::TaggedFollowing(treeNode x, TagType tag) // TaggedFollBelow(x,tag,root): returns the first node tagged tag with larger preorder than x // and not in the subtree of x. Returns NULLT if there is none. +/* treeNode XMLTree::TaggedFollowingBelow(treeNode x, TagType tag, treeNode ancestor) { // NULLT_IF (x == NULLT || x == Root() || x == ancestor); //Special optimisation, test for the following sibling first treeNode close = fast_find_close(Par, x); - /* - treeNode ns = close+1; - if (fast_inspect(Par,ns) == OP) { - TagType tagns = Tag(ns); - // cout << GetTagNameByRef(tagns) << endl; - //cout.flush(); - if (tagns == PCDATA_TAG_ID){ - close = ns+1; - ns = ns+2; - if (fast_inspect(Par,ns) != OP) - goto after; - tagns = Tag(ns); - }; - if (tagns == tag) - return ns; - }; - after: - */ treeNode s = tagpos2node(Tags->select_next(tag, close)); if (ancestor == Root() || s==NULLT || s < fast_find_close(Par,ancestor)) return s; else return NULLT; } +*/ treeNode XMLTree::TaggedFollowingBefore(treeNode x, TagType tag, treeNode closing) {