From b858bc31143609e050e067f1c08a3502be1e13ab Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 18 Feb 2011 12:59:19 +0000 Subject: [PATCH] . git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@1010 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- XMLTree.cpp | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/XMLTree.cpp b/XMLTree.cpp index a0815b8..fd46677 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -665,7 +665,7 @@ treeNode XMLTree::TaggedFollowingBelow(treeNode x, TagType tag, treeNode ancesto else return NULLT; } */ - + /* treeNode XMLTree::TaggedFollowingBefore(treeNode x, TagType tag, treeNode closing) { @@ -676,7 +676,7 @@ treeNode XMLTree::TaggedFollowingBefore(treeNode x, TagType tag, treeNode closin return s; } - + */ /* Here we inline TaggedFoll to find the min globally, and only at the end we check if the min is below the context node */ treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ancestor) @@ -695,13 +695,9 @@ treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ance TagIdSet::const_iterator tagit; - for (tagit = tags->begin(); tagit != tags->end(); tagit++) { + for (tagit = tags->begin(); tagit != tags->end(); ++tagit) { aux = tagpos2node(Tags->select_next(*tagit, close)); - - // The next sibling of x is guaranteed to be below ctx - // and is the node with lowest preorder which is after ctx. - // if we find it, we return early; if (aux == NULLT) continue; if ((min == NULLT) || (aux < min)) min = aux; }; @@ -709,14 +705,43 @@ treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ance // found the smallest node in preorder which is after x. // if ctx is the root node, just return what we found. - if (ancestor == Root()) return min; - // else check whether if is in below the ctx node - - NULLT_IF (min == NULLT || min >= fast_find_close(Par, ancestor)); + if (ancestor == Root() || min == NULLT || min < fast_find_close(Par, ancestor)) return min; + else return NULLT; - return min; + } + +treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode ancestor_closing) + { + + NULLT_IF(x==NULLT || x==Root()); + + treeNode close = fast_find_close(Par,x); + treeNode ns = close+1; + if ( (fast_inspect(Par,ns) == OP) && (tags->find(Tag(ns)) != tags->end())) + return ns; + + int i; + treeNode min = NULLT; + treeNode aux; + + + TagIdSet::const_iterator tagit; + for (tagit = tags->begin(); tagit != tags->end(); ++tagit) { + + aux = tagpos2node(Tags->select_next(*tagit, close)); + if (aux == NULLT) continue; + if ((min == NULLT) || (aux < min)) min = aux; + }; + + // found the smallest node in preorder which is after x. + // if ctx is the root node, just return what we found. + + if (ancestor_closing == Root() || min == NULLT || min < ancestor_closing) return min; + else return NULLT; } + +/* treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode closing) { @@ -748,7 +773,7 @@ treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode clo return min; } - +*/ // TaggedAncestor(x, tag): returns the closest ancestor of x tagged tag. Return // NULLT is there is none. -- 2.17.1