X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTreeBuilder.cpp;h=d9b083248a7082d3f94e706e66e7677c2fef4f22;hb=883743aa4d19900d312bd186df810a68ecd71cf8;hp=9c0fc6a0a5d13188578aa399ec0c96bda6dca4f0;hpb=1413ae2197d87e87571c9d8d6fc9f20f691fcea3;p=SXSI%2FXMLTree.git diff --git a/XMLTreeBuilder.cpp b/XMLTreeBuilder.cpp index 9c0fc6a..d9b0832 100644 --- a/XMLTreeBuilder.cpp +++ b/XMLTreeBuilder.cpp @@ -1,25 +1,33 @@ -#include "basics.h" +#include "common.h" #include "XMLTreeBuilder.h" - +#include "timings.h" +using std::string; XMLTreeBuilder::~XMLTreeBuilder(){ - + //free(par_aux); + free(tags_aux); + //delete other stuff. + } // OpenDocument(empty_texts): it starts the construction of the data structure for // the XML document. Parameter empty_texts indicates whether we index empty texts // in document or not. Returns a non-zero value upon success, NULLT in case of error. -int XMLTreeBuilder::OpenDocument(bool empty_texts, int sample_rate_text, bool dtc) +int XMLTreeBuilder::OpenDocument(bool empty_texts, + int sample_rate_text, + bool dtc, + TextCollectionBuilder::index_type_t index_type) { npar = 0; parArraySize = 1; disable_tc = dtc; - - + text_index_type = index_type; + STARTTIMER(); + par_aux = (pb *)umalloc(sizeof(pb)*parArraySize); - + tags_aux = (TagType *) umalloc(sizeof(TagType)); - + TagName = new vector(); tIdMap = new std::unordered_map(); @@ -27,6 +35,7 @@ int XMLTreeBuilder::OpenDocument(bool empty_texts, int sample_rate_text, bool dt REGISTER_TAG(TagName,tIdMap,ATTRIBUTE_OPEN_TAG); REGISTER_TAG(TagName,tIdMap,PCDATA_OPEN_TAG); REGISTER_TAG(TagName,tIdMap,ATTRIBUTE_DATA_OPEN_TAG); + REGISTER_TAG(TagName,tIdMap,CLOSING_TAG); REGISTER_TAG(TagName,tIdMap,DOCUMENT_CLOSE_TAG); REGISTER_TAG(TagName,tIdMap,ATTRIBUTE_CLOSE_TAG); REGISTER_TAG(TagName,tIdMap,PCDATA_CLOSE_TAG); @@ -35,8 +44,9 @@ int XMLTreeBuilder::OpenDocument(bool empty_texts, int sample_rate_text, bool dt if (disable_tc) TextBuilder = 0; - else - TextBuilder = new TextCollectionBuilder((unsigned)sample_rate_text); + else + TextBuilder = TextCollectionBuilder::create((unsigned)sample_rate_text, index_type); + Text = 0; empty_texts_aux = (unsigned int *)ucalloc(sizeof(unsigned int),1); eta_size = sizeof(unsigned int); @@ -44,34 +54,32 @@ int XMLTreeBuilder::OpenDocument(bool empty_texts, int sample_rate_text, bool dt } // CloseDocument(): it finishes the construction of the data structure for the XML -// document. Tree and tags are represented in the final form, dynamic data -// structures are made static, and the flag "finished" is set to true. After that, +// document. Tree and tags are represented in the final form, dynamic data +// structures are made static, and the flag "finished" is set to true. After that, // the data structure can be queried. XMLTree *XMLTreeBuilder::CloseDocument() - { + { //closing parenthesis for the tree root //par_aux = (pb *)urealloc(par_aux, sizeof(pb)*(1+npar/(8*sizeof(pb)))); //setbit(par_aux, npar, CP); //npar++; - + // makes the text collection static - if (!disable_tc) { - assert(Text == 0); - assert(TextBuilder != 0); - Text = TextBuilder->InitTextCollection(); - delete TextBuilder; - TextBuilder = 0; - } - + STOPTIMER(Parsing); + PRINTTIME("Parsing XML Document", Parsing); + XMLTree *T = new XMLTree(par_aux, - npar, + npar, TagName, tIdMap, - empty_texts_aux, // freed by the constructor - tags_aux, //freed by the constructor - Text, - disable_tc); - return T; + empty_texts_aux, // freed by the constructor + tags_aux, // freed by the constructor + TextBuilder, // freed by the constructor + disable_tc, + text_index_type); + tags_aux = 0; + empty_texts_aux = 0; + return T; } @@ -81,17 +89,21 @@ XMLTree *XMLTreeBuilder::CloseDocument() int XMLTreeBuilder::NewOpenTag(string tagname) { int i; - // inserts a new opening parentheses in the bit sequence if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis - par_aux = (pb *)urealloc(par_aux, sizeof(pb)*2*parArraySize); - parArraySize *= 2; - } - - setbit(par_aux,npar,OP); // marks a new opening parenthesis - + + // If array is already 1GB, be gentler when resizing: + if (sizeof(pb)*parArraySize >= 1024*1024*1024) + parArraySize += (128*1024*1024); + else + parArraySize *= 2; + par_aux = (pb *) urealloc(par_aux, sizeof(pb)*parArraySize); + }; + + bp_setbit(par_aux,npar,OP); // marks a new opening parenthesis + TagIdMapIT tag_id = tIdMap->find(tagname); - + if (tag_id == tIdMap->end()){ REGISTER_TAG(TagName,tIdMap,tagname); i = TagName->size() - 1; @@ -102,14 +114,15 @@ int XMLTreeBuilder::NewOpenTag(string tagname) if (tagname.compare(PCDATA_OPEN_TAG) == 0 || tagname.compare(ATTRIBUTE_DATA_OPEN_TAG) == 0){ }; - + + tags_aux = (TagType *) urealloc(tags_aux, sizeof(TagType)*(npar + 1)); - + tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags - + npar++; - - return 1; // success + + return 1; // success } @@ -119,30 +132,33 @@ int XMLTreeBuilder::NewOpenTag(string tagname) int XMLTreeBuilder::NewClosingTag(string tagname) { int i; - // inserts a new closing parentheses in the bit sequence if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis - par_aux = (pb *)urealloc(par_aux, sizeof(pb)*2*parArraySize); - parArraySize *= 2; - } - - setbit(par_aux,npar,CP); // marks a new closing parenthesis - - tagname.insert(0,"/"); + // If array is already 1GB, be gentler when resizing: + if (sizeof(pb)*parArraySize >= 1024*1024*1024) + parArraySize += (128*1024*1024); + else + parArraySize *= 2; + par_aux = (pb *)urealloc(par_aux, sizeof(pb)*parArraySize); + }; - TagIdMapIT tag_id = tIdMap->find(tagname); + bp_setbit(par_aux,npar,CP); // marks a new closing parenthesis - if (tag_id == tIdMap->end()){ - REGISTER_TAG(TagName,tIdMap,tagname); - i = TagName->size() - 1; - } - else - i = tag_id->second; + //tagname.insert(0,"/"); - tags_aux = (TagType *)urealloc(tags_aux, sizeof(TagType)*(npar + 1)); + //TagIdMapIT tag_id = tIdMap->find(tagname); + + // if (tag_id == tIdMap->end()){ + // REGISTER_TAG(TagName,tIdMap,tagname); + // i = TagName->size() - 1; + // } + // else + // i = tag_id->second; + + tags_aux = (TagType *)urealloc(tags_aux, sizeof(TagType)*(npar + 1)); + + tags_aux[npar] = CLOSING_TAG_ID; // inserts the new tag id within the preorder sequence of tags - tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags - npar++; return 1; // success @@ -163,7 +179,7 @@ int XMLTreeBuilder::NewText(string text) int n_eta_size = sizeof(uint)*(1+(npar-1)/(8*sizeof(uint))); //see basics.h, recalloc resizes and sets the new area to 0. - + empty_texts_aux = (uint *)urecalloc(empty_texts_aux,eta_size,n_eta_size); eta_size = n_eta_size; bitset(empty_texts_aux, npar-1); // marks the non-empty text with a 1 in the bit vector