From: Kim Nguyễn Date: Tue, 24 Apr 2012 14:14:17 +0000 (+0200) Subject: Revert "Optimize subtree_elements by calling find_close only once." X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2FXMLTree.git;a=commitdiff_plain;h=9b8afc78da8be3f210cf204b732d4c84ca5080d5 Revert "Optimize subtree_elements by calling find_close only once." This reverts commit e9b536b9310b8a3df206a62df73651656a2ec3cb. Return wrong results for the root node. --- diff --git a/xml-tree.cpp b/xml-tree.cpp index 84d42e2..8c0386e 100644 --- a/xml-tree.cpp +++ b/xml-tree.cpp @@ -344,18 +344,20 @@ xml_tree* xml_tree::load(int fd, char* name, bool load_tc, int sf) uint32_t xml_tree::subtree_elements(xml_tree::node_t x) const { - xml_tree::node_t fin = bp_find_close(par, x); - uint32_t size = (fin - x)/2; + + uint32_t size = bp_subtree_size(par, x); if (x == root()){ x = bp_first_child(par,x); size = size - 1; }; + int s = x + 2*size - 1; int ntext = - tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, fin) - + tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, s) - tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, x-1); size = size - ntext; + xml_tree::node_t fin = bp_find_close(par, x); xml_tree::node_t y = tags->select_next(xml_tree::ATTRIBUTE_OPEN_TAG_ID, x); while (y != xml_tree::NIL && y < fin){ size -= subtree_size(y);