From ba2654a4c24fdc31d33eb4947e532f7f0c045b42 Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 11 Feb 2011 10:26:45 +0000 Subject: [PATCH] Add NumTags method. git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@998 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- XMLTree.h | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/XMLTree.h b/XMLTree.h index 8671bae..93999a6 100644 --- 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()));\ (v)->push_back(t); } while (false) - // returns NULLT if the test is true #define NULLT_IF(x) do { if (x) return NULLT; } while (0) @@ -102,7 +101,7 @@ static inline int fast_find_close(bp *b,int s) return fwd_excess(b,s,-1); } -static int fast_inspect(bp* Par,treeNode i) +static inline int fast_inspect(bp* Par,treeNode i) { int j,l; j = i >> logD; @@ -116,13 +115,13 @@ static treeNode fast_first_child(bp *Par, treeNode x) return (fast_inspect(Par,x) == OP) ? x : NULLT; } -static treeNode fast_next_sibling(bp* Par,treeNode x) +inline static treeNode fast_next_sibling(bp* Par,treeNode x) { - x = fast_find_close(Par,x)+1; - return (fast_inspect(Par,x) == OP) ? x : NULLT; + treeNode y = fast_find_close(Par,x)+1; + return (fast_inspect(Par, y) == OP) ? y : NULLT; } -static bool fast_is_ancestor(bp * Par,treeNode x,treeNode y){ +inline static bool fast_is_ancestor(bp * Par,treeNode x,treeNode y){ return (x <= y) && ((x==0) || (y <= fast_find_close(Par,x))); } @@ -223,6 +222,12 @@ public: return tags_len/2; } + + /** NumTags() : Number of distinct tags */ + unsigned int NumTags() { + return TagName->size(); + } + /** SubtreeSize(x): the number of nodes (and attributes) in the subtree of * node x. */ int SubtreeSize(treeNode x); @@ -522,11 +527,21 @@ public: // The following are inlined here for speed /** Tag(x): returns the tag identifier of node x. */ - TagType Tag(treeNode x) { - if (tags_blen == 8) - return (TagType) (((uchar*)tags_fix)[(int) x]); - else - return (TagType) get_field(tags_fix,tags_blen, (int) x); + inline TagType Tag(treeNode x) const throw () { + if (tags_blen == 8) + return (TagType) (((uchar*)tags_fix)[(int) x]); + else { + size_t idxlen = x * tags_blen; + size_t j = idxlen % W; + size_t i = idxlen / W; + size_t offset = W - tags_blen; + size_t offset2 = offset - j; + size_t w = tags_fix[i]; + return (offset2 >= 0) + ? ( w << offset2 ) >> offset + : ( w >> j) | (tags_fix[i+1] << (W+offset2)) >> offset; + }; + } /** FirstChild(x): returns the first child of node x, or NULLT if the node is a leaf @@ -589,7 +604,7 @@ public: /** TaggedDesc(x,tag): returns the first node tagged tag with larger * preorder than x and within the subtree of x. Returns NULT if there * is none. */ - treeNode TaggedDescendant(treeNode x, TagType tag) + inline treeNode TaggedDescendant(treeNode x, TagType tag) { int s = (int) Tags->select_next(tag,node2tagpos(x)); @@ -600,7 +615,7 @@ public: return (fast_is_ancestor(Par,x,y) ? y : NULLT); }; - treeNode TaggedFollowingBelow(treeNode x, TagType tag,treeNode ancestor) + inline treeNode TaggedFollowingBelow(treeNode x, TagType tag,treeNode ancestor) { treeNode close = fast_find_close(Par, x); treeNode s = tagpos2node(Tags->select_next(tag, close)); -- 2.17.1