inline TaggedChild/TaggedFollowingSibling
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 21 Feb 2011 04:58:32 +0000 (04:58 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 21 Feb 2011 04:58:32 +0000 (04:58 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@1015 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h

index fd46677..fd2c6de 100644 (file)
@@ -26,7 +26,6 @@ static int bits8 (int t ) {
 \r
 \r
 \r
-\r
 static treeNode fast_sibling(bp* Par,treeNode x,TagType tag){\r
 \r
   if (tag == PCDATA_TAG_ID){\r
@@ -36,9 +35,7 @@ static treeNode fast_sibling(bp* Par,treeNode x,TagType tag){
 \r
 }\r
 \r
-static bool fast_isleaf(bp* Par,treeNode x){\r
-  return (fast_inspect(Par,x+1) == CP ? true : false);\r
-}\r
+\r
 \r
 \r
 inline uint get_field_no_power(uint *A, uint len, uint index) {\r
@@ -526,6 +523,7 @@ treeNode XMLTree::PrevSibling(treeNode x)
 // TaggedChild(x,tag): returns the first child of node x tagged tag, or NULLT if there is none.\r
 // Because of the balanced-parentheses representation of the tree, this operation is not supported\r
 // efficiently, just iterating among the children of node x until finding the desired child.\r
+/*\r
 treeNode XMLTree::TaggedChild(treeNode x, TagType tag) \r
  {\r
    \r
@@ -552,7 +550,7 @@ treeNode XMLTree::TaggedFollowingSibling(treeNode x, TagType tag)
   }\r
   return NULLT; // no such sibling was found   \r
 }\r
-\r
+*/\r
 treeNode XMLTree::SelectChild(treeNode x, TagIdSet *tags)\r
 {\r
   \r
index 90f6b15..95ec450 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -109,6 +109,10 @@ static inline int fast_inspect(bp* Par,treeNode i)
   return (Par->B[j] >> (D-1-l)) & 1;\r
 }\r
 \r
+static bool fast_isleaf(bp* Par,treeNode x){\r
+  return (fast_inspect(Par, x+1) == CP);\r
+}\r
+\r
 static treeNode fast_first_child(bp *Par, treeNode x)\r
 {\r
   x = x+1;\r
@@ -316,13 +320,12 @@ public:
     * NULLT if there is none. Because of the balanced-parentheses representation \r
     * of the tree, this operation is not supported efficiently, just iterating \r
     * among the children of node x until finding the desired child. */\r
-   treeNode TaggedChild(treeNode x, TagType tag);\r
+\r
    \r
    treeNode SelectChild(treeNode x, TagIdSet * tags);\r
 \r
    /** TaggedFollowingSibling(x,tag): returns the first sibling of node x tagged tag, or \r
     *  NULLT if there is none. */\r
-   treeNode TaggedFollowingSibling(treeNode x, TagType tag);\r
    \r
    treeNode SelectFollowingSibling(treeNode x, TagIdSet * tags);\r
 \r
@@ -641,10 +644,35 @@ public:
          else return NULLT;\r
   };\r
     \r
+// TaggedSibling(x,tag): returns the first sibling of node x tagged tag, or NULLT if there is none.\r
+treeNode TaggedFollowingSibling(treeNode x, TagType tag)\r
+{\r
+  NULLT_IF(x==NULLT);\r
+  treeNode sibling = x;\r
+  TagType ctag;\r
+  while ((sibling = fast_next_sibling(Par, sibling)) != NULLT) {\r
+    ctag = Tag(sibling);\r
+    if (ctag == tag) return sibling; \r
+  }\r
+  return NULLT; \r
 };\r
 \r
+treeNode TaggedChild(treeNode x, TagType tag) \r
+{\r
+   \r
+   NULLT_IF(x==NULLT || fast_isleaf(Par,x));\r
+   treeNode child;   \r
+   child = fast_first_child(Par, x);\r
+\r
+   if (Tag(child) == tag)\r
+     return child;\r
+   else\r
+     return TaggedFollowingSibling(child, tag);\r
+};\r
 \r
 \r
+};\r
+\r
 \r
 #endif\r
 \r