X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=c87c6dc008443bb723a450f7ecef9aff560598a3;hb=f97501e008660c0363f0fe643be09de66efd3533;hp=db9814c7b2cc4a908e5ab83f7e3258bef4fce37a;hpb=9c696a1b1a7034794b3768e4e1e40db86e87ebbb;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index db9814c..c87c6dc 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -1,9 +1,12 @@ #include "basics.h" -//#include -#include #include "XMLTree.h" #include "timings.h" #include +using std::cout; +using std::endl; +using std::min; +using std::string; + // functions to convert tag positions to the corresponding tree node and viceversa. // These are implemented in order to be able to change the tree and Tags representations, // without affecting the code so much. @@ -255,7 +258,7 @@ XMLTree *XMLTree::Load(int fd, bool load_tc,int sample_factor) XMLTree *XML_Tree; int i; - + buffer[1023] = '\0'; fp = fdopen(fd, "r"); @@ -269,23 +272,21 @@ XMLTree *XMLTree::Load(int fd, bool load_tc,int sample_factor) PRINTTIME("Loading parenthesis struct", Loading); STARTTIMER(); - XML_Tree->TagName = new vector(); - XML_Tree->tIdMap = new std::unordered_map(); - - string s; + XML_Tree->TagName = new std::vector(); + XML_Tree->tIdMap = new std::unordered_map(); + std::string s; int ntags; // Load the tag names ufread(&ntags, sizeof(int), 1, fp); for (i=0; iTagName->push_back(s); + XML_Tree->TagName->push_back(s); XML_Tree->tIdMap->insert(std::make_pair(s,i)); }; @@ -366,7 +367,7 @@ int XMLTree::SubtreeTags(treeNode x, TagType tag) int s = x + 2*subtree_size(Par, x) - 1; - return Tags->rank(tag, s) - Tags->rank(tag, node2tagpos(x)-1); + return (Tags->rank(tag, s) - Tags->rank(tag, node2tagpos(x)-1))+1; } int XMLTree::SubtreeElements(treeNode x) { @@ -538,22 +539,6 @@ treeNode XMLTree::NextElement(treeNode x) } else return x; } -value XMLTree::CamlFirstElement(value x) -{ - return Val_int(FirstElement(Int_val(x))); -} -value XMLTree::CamlNextElement(value x) -{ - return Val_int(NextElement(Int_val(x))); -} - -extern "C" value caml_cpp_fast_first_element(value xmltree, value node){ - return XMLTREE(xmltree)->CamlFirstElement(node); -} - -extern "C" value caml_cpp_fast_next_element(value xmltree, value node){ - return XMLTREE(xmltree)->CamlNextElement(node); -} // LastChild(x): returns the last child of node x. treeNode XMLTree::LastChild(treeNode x)