From 5a878b1d30583985f5d91d12de3b3aa19259434a Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 21 Feb 2011 04:58:32 +0000 Subject: [PATCH] inline TaggedChild/TaggedFollowingSibling git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@1015 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- XMLTree.cpp | 8 +++----- XMLTree.h | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/XMLTree.cpp b/XMLTree.cpp index fd46677..fd2c6de 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -26,7 +26,6 @@ static int bits8 (int t ) { - static treeNode fast_sibling(bp* Par,treeNode x,TagType tag){ if (tag == PCDATA_TAG_ID){ @@ -36,9 +35,7 @@ static treeNode fast_sibling(bp* Par,treeNode x,TagType tag){ } -static bool fast_isleaf(bp* Par,treeNode x){ - return (fast_inspect(Par,x+1) == CP ? true : false); -} + inline uint get_field_no_power(uint *A, uint len, uint index) { @@ -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. // Because of the balanced-parentheses representation of the tree, this operation is not supported // efficiently, just iterating among the children of node x until finding the desired child. +/* treeNode XMLTree::TaggedChild(treeNode x, TagType tag) { @@ -552,7 +550,7 @@ treeNode XMLTree::TaggedFollowingSibling(treeNode x, TagType tag) } return NULLT; // no such sibling was found } - +*/ treeNode XMLTree::SelectChild(treeNode x, TagIdSet *tags) { diff --git a/XMLTree.h b/XMLTree.h index 90f6b15..95ec450 100644 --- 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; } +static bool fast_isleaf(bp* Par,treeNode x){ + return (fast_inspect(Par, x+1) == CP); +} + static treeNode fast_first_child(bp *Par, treeNode x) { x = x+1; @@ -316,13 +320,12 @@ public: * NULLT if there is none. Because of the balanced-parentheses representation * of the tree, this operation is not supported efficiently, just iterating * among the children of node x until finding the desired child. */ - treeNode TaggedChild(treeNode x, TagType tag); + treeNode SelectChild(treeNode x, TagIdSet * tags); /** TaggedFollowingSibling(x,tag): returns the first sibling of node x tagged tag, or * NULLT if there is none. */ - treeNode TaggedFollowingSibling(treeNode x, TagType tag); treeNode SelectFollowingSibling(treeNode x, TagIdSet * tags); @@ -641,10 +644,35 @@ public: else return NULLT; }; +// TaggedSibling(x,tag): returns the first sibling of node x tagged tag, or NULLT if there is none. +treeNode TaggedFollowingSibling(treeNode x, TagType tag) +{ + NULLT_IF(x==NULLT); + treeNode sibling = x; + TagType ctag; + while ((sibling = fast_next_sibling(Par, sibling)) != NULLT) { + ctag = Tag(sibling); + if (ctag == tag) return sibling; + } + return NULLT; }; +treeNode TaggedChild(treeNode x, TagType tag) +{ + + NULLT_IF(x==NULLT || fast_isleaf(Par,x)); + treeNode child; + child = fast_first_child(Par, x); + + if (Tag(child) == tag) + return child; + else + return TaggedFollowingSibling(child, tag); +}; +}; + #endif -- 2.17.1