Add NumTags method.
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 11 Feb 2011 10:26:45 +0000 (10:26 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 11 Feb 2011 10:26:45 +0000 (10:26 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@998 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.h

index 8671bae..93999a6 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -91,7 +91,6 @@ typedef TagIdMap::const_iterator TagIdMapIT;
 #define REGISTER_TAG(v,h,t) do { (h)->insert(std::make_pair((t),(v)->size()));\\r
     (v)->push_back(t); } while (false)\r
 \r
-\r
 // returns NULLT if the test is true\r
 #define NULLT_IF(x)  do { if (x) return NULLT; } while (0)\r
 \r
@@ -102,7 +101,7 @@ static inline int fast_find_close(bp *b,int s)
   return fwd_excess(b,s,-1);\r
 }\r
 \r
-static int fast_inspect(bp* Par,treeNode i)\r
+static inline int fast_inspect(bp* Par,treeNode i)\r
 {\r
   int j,l;\r
   j = i >> logD;\r
@@ -116,13 +115,13 @@ static treeNode fast_first_child(bp *Par, treeNode x)
   return (fast_inspect(Par,x) == OP) ? x : NULLT;\r
 }\r
 \r
-static treeNode fast_next_sibling(bp* Par,treeNode x)\r
+inline static treeNode fast_next_sibling(bp* Par,treeNode x)\r
 {\r
-  x = fast_find_close(Par,x)+1;\r
-  return (fast_inspect(Par,x) == OP) ? x : NULLT;\r
+  treeNode y = fast_find_close(Par,x)+1;\r
+  return (fast_inspect(Par, y) == OP) ? y : NULLT;\r
 }\r
 \r
-static bool fast_is_ancestor(bp * Par,treeNode x,treeNode y){\r
+inline static bool fast_is_ancestor(bp * Par,treeNode x,treeNode y){\r
   return (x <= y) && ((x==0) || (y <= fast_find_close(Par,x)));\r
 }\r
 \r
@@ -223,6 +222,12 @@ public:
      return tags_len/2;\r
    }\r
 \r
+\r
+   /** NumTags() : Number of distinct tags */\r
+   unsigned int NumTags() {\r
+          return TagName->size();\r
+   }\r
+\r
    /** SubtreeSize(x): the number of nodes (and attributes) in the subtree of \r
     * node x. */\r
    int SubtreeSize(treeNode x);\r
@@ -522,11 +527,21 @@ public:
   // The following are inlined here for speed\r
   /** Tag(x): returns the tag identifier of node x. */\r
 \r
-  TagType Tag(treeNode x) {\r
-    if (tags_blen == 8)\r
-      return  (TagType) (((uchar*)tags_fix)[(int) x]);\r
-    else\r
-      return (TagType) get_field(tags_fix,tags_blen, (int) x);\r
+   inline TagType Tag(treeNode x) const throw () {\r
+         if (tags_blen == 8)\r
+                 return  (TagType) (((uchar*)tags_fix)[(int) x]);\r
+         else { \r
+         size_t idxlen = x * tags_blen;\r
+         size_t j = idxlen % W;\r
+         size_t i = idxlen / W; \r
+         size_t offset = W - tags_blen;\r
+         size_t offset2 = offset - j;\r
+         size_t w = tags_fix[i];\r
+         return (offset2 >= 0)\r
+                 ? ( w << offset2 ) >> offset\r
+                 : ( w >> j) | (tags_fix[i+1] << (W+offset2)) >> offset;\r
+         }; \r
+\r
   }\r
 \r
      /** FirstChild(x): returns the first child of node x, or NULLT if the node is a leaf\r
@@ -589,7 +604,7 @@ public:
      /** TaggedDesc(x,tag): returns the first node tagged tag with larger \r
     * preorder than x and within the subtree of x. Returns NULT if there \r
     * is none. */\r
-  treeNode TaggedDescendant(treeNode x, TagType tag)\r
+  inline treeNode TaggedDescendant(treeNode x, TagType tag)\r
   {\r
     \r
          int s = (int) Tags->select_next(tag,node2tagpos(x));\r
@@ -600,7 +615,7 @@ public:
          return (fast_is_ancestor(Par,x,y) ? y : NULLT);\r
   };\r
   \r
-  treeNode TaggedFollowingBelow(treeNode x, TagType tag,treeNode ancestor)\r
+  inline treeNode TaggedFollowingBelow(treeNode x, TagType tag,treeNode ancestor)\r
   {\r
          treeNode close = fast_find_close(Par, x);\r
          treeNode s = tagpos2node(Tags->select_next(tag, close));\r