Fix a libcds bug:
[SXSI/XMLTree.git] / xml-tree-inc.hpp
index cd8db71..bb70513 100644 (file)
@@ -7,17 +7,6 @@
 
 #include <cstdio>
 
-#if 0
-#define ASSERT_NODE(orig, res) do {                                     \
-    if (res < -1 || res >= par->n|| (res != -1 && res < orig))          \
-    fprintf(stderr,                                                     \
-      "Assertion failure: original node %i, result %i, line %i\n",      \
-            orig, res, __LINE__);                                       \
-  } while (0)
-#else
-#define ASSERT_NODE(orig, res)
-#endif
-
 inline uint32_t xml_tree::size() const
 {
   return tag_seq_len / 2;
@@ -47,11 +36,30 @@ xml_tree::subtree_tags(xml_tree::node_t x, xml_tree::tag_t label) const
   };
 }
 
+inline uint32_t xml_tree::subtree_elements(xml_tree::node_t x,
+                                          xml_tree::tag_t *atts) 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);
+  return (uint32_t) size;
+
+}
+
 inline bool xml_tree::is_leaf(xml_tree::node_t x) const
 {
   return !bp_inspect(this->par, x+1);
 }
 
+inline bool xml_tree::is_open(xml_tree::node_t x) const
+{
+  return bp_inspect(this->par, x);
+}
+
 inline bool xml_tree::is_ancestor(xml_tree::node_t x,
                                   xml_tree::node_t y) const
 {
@@ -100,7 +108,6 @@ inline xml_tree::node_t xml_tree::parent(xml_tree::node_t x) const
 inline xml_tree::node_t xml_tree::first_child(node_t x) const
 {
   xml_tree::node_t result = bp_first_child(this->par, x);
-  ASSERT_NODE(x, result);
   return result;
 }
 
@@ -115,7 +122,6 @@ inline xml_tree::node_t xml_tree::last_child(xml_tree::node_t x) const
 inline xml_tree::node_t xml_tree::next_sibling(xml_tree::node_t x) const
 {
   xml_tree::node_t result = bp_next_sibling(this->par, x);
-  ASSERT_NODE(x, result);
   return result;
 }
 
@@ -185,8 +191,6 @@ inline xml_tree::node_t xml_tree::tagged_child(xml_tree::node_t x,
     return c;
   else
     return tagged_sibling(c, t);
-  /*  ASSERT_NODE(x, result);
-      return result;*/
 }
 
 inline xml_tree::node_t xml_tree::tagged_sibling(xml_tree::node_t x,
@@ -196,13 +200,10 @@ inline xml_tree::node_t xml_tree::tagged_sibling(xml_tree::node_t x,
   xml_tree::tag_t stag;
   while (sibling  != xml_tree::NIL) {
     stag = tag(sibling);
-    if (stag == t) {
-      ASSERT_NODE(x, sibling);
+    if (stag == t)
       return  sibling;
-    }
     sibling = next_sibling(sibling);
   };
-  ASSERT_NODE(x, sibling);
   return sibling;
 }
 
@@ -219,7 +220,8 @@ inline SXSI::TextCollection *xml_tree::get_text_collection() const
 
 inline xml_tree::node_t xml_tree::parent_node(int32_t d) const
 {
-  return (xml_tree::node_t) text_positions->select1(d + 1);
+  xml_tree::node_t res = text_positions->select1(d+1);
+  return (xml_tree::node_t) res;
 }
 
 inline SXSI::TextCollection::document_result