X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=xml-tree-inc.hpp;h=18c91e3dad2564b2cd5b06cfd8158d107ff1ad37;hb=HEAD;hp=30a321e052c05f5c835811c1bfdcb3c89bc07500;hpb=2b67e586d2ea45d87648ac3977306139110c4e78;p=SXSI%2FXMLTree.git diff --git a/xml-tree-inc.hpp b/xml-tree-inc.hpp index 30a321e..18c91e3 100644 --- a/xml-tree-inc.hpp +++ b/xml-tree-inc.hpp @@ -28,24 +28,25 @@ xml_tree::subtree_tags(xml_tree::node_t x, xml_tree::tag_t label) const xml_tree::node_t y = bp_find_close(this->par, x); if (y - x < 10) { uint32_t count = 0; - for(xml_tree::node_t i = x; i < y; i++) + for (xml_tree::node_t i = x; i <= y; ++i) count += (tag(i) == label); return count; } else { - return tags[label]->rank(y) - tags[label]->rank(x); - }; + return tags[label]->rank(y) - tags[label]->rank(x); + } } -inline uint32_t xml_tree::subtree_elements(xml_tree::node_t x, - xml_tree::tag_t *atts) const +inline uint32_t xml_tree::subtree_elements(xml_tree::node_t x) const { int32_t size = bp_subtree_size(par, x) - 1; if (size <= 0) return 0; - size -= subtree_tags(x, xml_tree::PCDATA_OPEN_TAG_ID); - if (size < 3) return (uint32_t) size; - for(; *atts != xml_tree::NIL_TAG_ID; atts++) - size -= subtree_tags(x, *atts); + uint32_t num_texts = subtree_tags(x, xml_tree::PCDATA_OPEN_TAG_ID); + uint32_t num_atts = subtree_tags(x, xml_tree::ATTRIBUTE_OPEN_TAG_ID); + uint32_t num_att_data = subtree_tags(x, xml_tree::ATTRIBUTE_DATA_OPEN_TAG_ID); + size -= num_texts; + size -= num_atts; + size -= 2*num_att_data; return (uint32_t) size; } @@ -163,7 +164,7 @@ inline xml_tree::node_t xml_tree::tagged_next_close(xml_tree::node_t x, xml_tree::tag_t label) const { xml_tree::node_t i=x; - for(xml_tree::node_t i = x+1; i < std::min(x+100, this->par->n); i++) + for(i = x+1; i < std::min(x+100, this->par->n); i++) if (tag(i) == label) return i;