.
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 18 Feb 2011 12:59:19 +0000 (12:59 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 18 Feb 2011 12:59:19 +0000 (12:59 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@1010 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp

index a0815b8..fd46677 100644 (file)
@@ -665,7 +665,7 @@ treeNode XMLTree::TaggedFollowingBelow(treeNode x, TagType tag, treeNode ancesto
   else return NULLT;\r
 } \r
 */\r
-\r
+ /*\r
 treeNode XMLTree::TaggedFollowingBefore(treeNode x, TagType tag, treeNode closing)\r
 {\r
 \r
@@ -676,7 +676,7 @@ treeNode XMLTree::TaggedFollowingBefore(treeNode x, TagType tag, treeNode closin
   \r
   return s;\r
 } \r
-\r
+ */\r
 /* Here we inline TaggedFoll to find the min globally, and only at the end\r
    we check if the min is below the context node */\r
 treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ancestor)\r
@@ -695,13 +695,9 @@ treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ance
   \r
 \r
    TagIdSet::const_iterator tagit;\r
-   for (tagit = tags->begin(); tagit != tags->end(); tagit++) {\r
+   for (tagit = tags->begin(); tagit != tags->end(); ++tagit) {\r
 \r
      aux = tagpos2node(Tags->select_next(*tagit, close));\r
-     \r
-     // The next sibling of x is guaranteed to be below ctx\r
-     // and is the node with lowest preorder which is after ctx.\r
-     // if we find it, we return early;         \r
      if (aux == NULLT) continue;\r
      if ((min == NULLT) || (aux < min)) min = aux;\r
    };\r
@@ -709,14 +705,43 @@ treeNode XMLTree::SelectFollowingBelow(treeNode x, TagIdSet *tags, treeNode ance
    // found the smallest node in preorder which is after x.\r
    // if ctx is the root node, just return what we found.\r
 \r
-   if (ancestor == Root()) return min;\r
-   // else check whether if is in below the ctx node\r
-\r
-   NULLT_IF (min == NULLT || min >= fast_find_close(Par, ancestor));\r
+   if (ancestor == Root() || min == NULLT || min < fast_find_close(Par, ancestor)) return min;\r
+   else return NULLT;\r
    \r
-   return min;\r
+ }\r
+\r
+treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode ancestor_closing)\r
+ {\r
+\r
+   NULLT_IF(x==NULLT || x==Root());\r
+\r
+   treeNode close = fast_find_close(Par,x);\r
+   treeNode ns = close+1;\r
+   if ( (fast_inspect(Par,ns) == OP) && (tags->find(Tag(ns)) != tags->end()))\r
+     return ns;\r
+\r
+   int i;\r
+   treeNode min = NULLT;\r
+   treeNode aux;\r
+  \r
+\r
+   TagIdSet::const_iterator tagit;\r
+   for (tagit = tags->begin(); tagit != tags->end(); ++tagit) {\r
+\r
+     aux = tagpos2node(Tags->select_next(*tagit, close));\r
+     if (aux == NULLT) continue;\r
+     if ((min == NULLT) || (aux < min)) min = aux;\r
+   };\r
+     \r
+   // found the smallest node in preorder which is after x.\r
+   // if ctx is the root node, just return what we found.\r
+\r
+   if (ancestor_closing == Root() || min == NULLT || min < ancestor_closing) return min;\r
+   else return NULLT;\r
    \r
  }\r
+\r
+/*\r
 treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode closing)\r
  {\r
 \r
@@ -748,7 +773,7 @@ treeNode XMLTree::SelectFollowingBefore(treeNode x, TagIdSet *tags, treeNode clo
    return min;\r
    \r
  }\r
-\r
+*/\r
 \r
 // TaggedAncestor(x, tag): returns the closest ancestor of x tagged tag. Return\r
 // NULLT is there is none.\r