From aad0ef1d1e05d23d3466e263160cda0a8fdf6866 Mon Sep 17 00:00:00 2001 From: kim Date: Wed, 9 Nov 2011 15:41:41 +0000 Subject: [PATCH] Add debugging option to make Clean-up XMLTreeBuilder git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@1171 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- Makefile | 11 ++++++-- XMLTreeBuilder.cpp | 65 +++++++++++++++++++++++++--------------------- XMLTreeBuilder.h | 38 +++++++++++++-------------- 3 files changed, 63 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 2eb3662..0727f78 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,20 @@ else HIDE=@ endif -OPT_FLAGS=-O4 $(POPCOUNT_FLAG) -fno-PIC -static +ifeq ($(DEBUG), true) + OPT_FLAGS=-O0 -g $(POPCOUNT_FLAG) -fno-PIC -static +else + OPT_FLAGS=-O4 $(POPCOUNT_FLAG) -fno-PIC -static +endif + + + INC_FLAGS=-I./libcds/includes/ -I. CFLAGS= $(INC_FLAGS) $(OPT_FLAGS) CXXFLAGS= -std=c++0x $(INC_FLAGS) $(OPT_FLAGS) CC=g++ -LIBCDS_A=libcds/lib/libcds.a +LIBCDS_A=libcds/lib/libcds.a OBJECTS_TCO= TextCollection/TextCollection.o \ TextCollection/TextCollectionBuilder.o \ TextCollection/RLCSABuilder.o \ diff --git a/XMLTreeBuilder.cpp b/XMLTreeBuilder.cpp index 9c7e3f6..68c5bf3 100644 --- a/XMLTreeBuilder.cpp +++ b/XMLTreeBuilder.cpp @@ -4,13 +4,16 @@ 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 XMLTreeBuilder::OpenDocument(bool empty_texts, int sample_rate_text, bool dtc, TextCollectionBuilder::index_type_t index_type) @@ -20,11 +23,11 @@ int XMLTreeBuilder::OpenDocument(bool empty_texts, 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(); @@ -41,7 +44,7 @@ int XMLTreeBuilder::OpenDocument(bool empty_texts, if (disable_tc) TextBuilder = 0; - else + else TextBuilder = TextCollectionBuilder::create((unsigned)sample_rate_text, index_type); Text = 0; @@ -51,16 +54,16 @@ int XMLTreeBuilder::OpenDocument(bool empty_texts, } // 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 STOPTIMER(Parsing); PRINTTIME("Parsing XML Document", Parsing); @@ -76,17 +79,19 @@ XMLTree *XMLTreeBuilder::CloseDocument() PRINTTIME("Building TextCollection", Building); } - + XMLTree *T = new XMLTree(par_aux, - npar, + npar, TagName, tIdMap, - empty_texts_aux, // freed by the constructor - tags_aux, //freed by the constructor + empty_texts_aux, // freed by the constructor + tags_aux, // freed by the constructor Text, disable_tc, text_index_type); - return T; + tags_aux = 0; + empty_texts_aux = 0; + return T; } @@ -96,17 +101,17 @@ 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 - + TagIdMapIT tag_id = tIdMap->find(tagname); - + if (tag_id == tIdMap->end()){ REGISTER_TAG(TagName,tIdMap,tagname); i = TagName->size() - 1; @@ -117,14 +122,14 @@ 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 } @@ -134,18 +139,18 @@ 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,"/"); - //TagIdMapIT tag_id = tIdMap->find(tagname); + //TagIdMapIT tag_id = tIdMap->find(tagname); // if (tag_id == tIdMap->end()){ // REGISTER_TAG(TagName,tIdMap,tagname); @@ -157,7 +162,7 @@ int XMLTreeBuilder::NewClosingTag(string tagname) 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 - + npar++; return 1; // success @@ -178,7 +183,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 diff --git a/XMLTreeBuilder.h b/XMLTreeBuilder.h index c7a9036..8ac4eba 100644 --- a/XMLTreeBuilder.h +++ b/XMLTreeBuilder.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ******************************************************************************/ + ******************************************************************************/ #ifndef XMLTREEBUILDER_H_ #define XMLTREEBUILDER_H_ @@ -43,22 +43,22 @@ using SXSI::TextCollectionBuilder; class XMLTreeBuilder { - + /** Array containing the balanced parentheses sequence */ pb *par_aux; int parArraySize; int npar; - /** Mapping from tag identifer to tag name */ + /** Mapping from tag identifer to tag name */ std::vector *TagName; TagIdMap * tIdMap; /** Array containing the sequence of tags */ TagType *tags_aux; - + /** The texts in the XML document */ TextCollectionBuilder *TextBuilder; TextCollection *Text; - + /** The texts in the XML document (cached for faster display) */ std::vector *CachedText; @@ -73,37 +73,37 @@ public: XMLTreeBuilder() {;}; ~XMLTreeBuilder(); - + /** OpenDocument(sample_rate_text,dtc): initilizes the construction - * of the data structure for the XML document. Parameter + * of the data structure for the XML document. Parameter * sample_rate_text indicates the sampling rate for the text searching data - * structures (small values get faster searching but a bigger space + * structures (small values get faster searching but a bigger space * requirement). dtc disable the use of the TextCollection * (i.e. everything is considered an empty text *) - * Returns a non-zero value upon success, NULLT in case of + * Returns a non-zero value upon success, NULLT in case of * error. */ int OpenDocument(bool empty_texts, int sample_rate_text, bool dtc, TextCollectionBuilder::index_type_t index_type); - /** CloseDocument(): finishes the construction of the data structure for - * the XML document. Tree and tags are represented in the final form, + /** CloseDocument(): 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, returning the resulting * XMLTree. After that, the XMLTree data structure can be queried. */ XMLTree *CloseDocument(); - /** NewOpenTag(tagname): indicates the event of finding a new opening tag - * in the document. Tag name is given. Returns a non-zero value upon + /** NewOpenTag(tagname): indicates the event of finding a new opening tag + * in the document. Tag name is given. Returns a non-zero value upon * success, and returns NULLT in case of error. */ int NewOpenTag(std::string tagname); - + /** NewClosingTag(tagname): indicates the event of finding a new closing tag - * in the document. Tag name is given. Returns a non-zero value upon + * in the document. Tag name is given. Returns a non-zero value upon * success, and returns NULLT in case of error. */ int NewClosingTag(std::string tagname); - - /** NewText(s): indicates the event of finding a new text s in - * the document. The new text is inserted within the text collection. - * Returns a non-zero value upon success, NULLT in case of error. + + /** NewText(s): indicates the event of finding a new text s in + * the document. The new text is inserted within the text collection. + * Returns a non-zero value upon success, NULLT in case of error. * If the string is empty, which is legal in attributes, then * the string the sequence '\0x01\0x00' is inserted in the TextCollection * It is ok to do so since a non printable character cannot occur in an XML document -- 2.17.1