X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=21658e99c323c4aaaff8b72e385d8580542bddf4;hb=52cb7bbcda67f4676335cdd4eb96d4d87ad1445d;hp=ea12fad9080f4a09c3f864d694e40a149f6eb3e2;hpb=e421727c5a512154cf2c3ff4cf8390eb88d527d7;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index ea12fad..21658e9 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -1,6 +1,5 @@ - #include "XMLTree.h" - +#include // 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. @@ -102,7 +101,7 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text) if (!(XML_Tree->indexing_empty_texts)) XML_Tree->EBVector = static_bitsequence_rrr02::load(fp); // loads the tags - XML_Tree->Tags = static_sequence_wvtree::load(fp); + XML_Tree->Tags = static_sequence::load(fp); // loads the texts XML_Tree->Text->Load(fp,sample_rate_text); @@ -127,16 +126,16 @@ XMLTree::~XMLTree() free(TagName); if (!indexing_empty_texts) { - EBVector->~static_bitsequence_rrr02(); + //EBVector->~static_bitsequence_rrr02(); delete EBVector; EBVector = NULL; } - Tags->~static_sequence_wvtree(); + //Tags->~static_sequence_wvtree(); delete Tags; Tags = NULL; - Text->~TextCollection(); + //Text->~TextCollection(); delete Text; Text = NULL; @@ -312,8 +311,10 @@ treeNode XMLTree::Parent(treeNode x) fprintf(stderr, "Error: data structure has not been constructed properly\n"); exit(1); } - - return parent(Par, x); + if (x == Root()) + return NULLT; + else + return parent(Par, x); } // Child(x,i): returns the i-th child of node x, assuming it exists. @@ -346,7 +347,9 @@ treeNode XMLTree::NextSibling(treeNode x) fprintf(stderr, "Error: data structure has not been constructed properly\n"); exit(1); } - + if (x == Root()) + return NULLT; + return next_sibling(Par, x); } @@ -572,19 +575,18 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text) initialized = true; finished = false; npar = 0; - ntagnames = 0; - + parArraySize = 1; + ntagnames = 0; + indexing_empty_texts = empty_texts; - par_aux = (pb *)malloc(sizeof(pb)); + par_aux = (pb *)malloc(sizeof(pb)*parArraySize); if (!par_aux) { fprintf(stderr, "Error: not enough memory\n"); return NULLT; } - setbit(par_aux,npar,OP); // marks a new opening parenthesis for the tree root - npar++; - tags_aux = (TagType *)malloc(sizeof(TagType)); + tags_aux = (TagType *) malloc(sizeof(TagType)); if (!tags_aux) { fprintf(stderr, "Error: not enough memory\n"); return NULLT; @@ -622,18 +624,20 @@ int XMLTree::CloseDocument() fprintf(stderr, "Error: not enough memory\n"); return NULLT; } - setbit(par_aux,npar,CP); - npar++; // creates the data structure for the tree topology - Par = (bp *)malloc(sizeof(bp)); + Par = (bp *)malloc(sizeof(bp)); bp_construct(Par, npar, par_aux, OPT_DEGREE|0); // creates structure for tags - alphabet_mapper * am = new alphabet_mapper_none(); - static_bitsequence_builder * bmb = new static_bitsequence_builder_rrr02(32); - wt_coder * wtc = new wt_coder_huff((uint *)tags_aux,npar-1,am); - Tags = new static_sequence_wvtree((uint *) tags_aux, (uint) npar-1, wtc, bmb, am); + static_bitsequence_builder * bmb = new static_bitsequence_builder_brw32(20); + static_permutation_builder * pmb = new static_permutation_builder_mrrr(PERM_SAMPLE, bmb); + static_sequence_builder * ssb = new static_sequence_builder_gmr_chunk(bmb, pmb); + Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,2*ntagnames, bmb, ssb); + + delete bmb; + delete pmb; + delete ssb; // makes the text collection static Text->MakeStatic(); @@ -660,11 +664,16 @@ int XMLTree::NewOpenTag(unsigned char *tagname) } // inserts a new opening parentheses in the bit sequence - par_aux = (pb *)realloc(par_aux, sizeof(pb)*(1+npar/(8*sizeof(pb)))); + if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis + par_aux = (pb *)realloc(par_aux, sizeof(pb)*2*parArraySize); + parArraySize *= 2; + } + if (!par_aux) { fprintf(stderr, "Error: not enough memory\n"); return NULLT; } + setbit(par_aux,npar,OP); // marks a new opening parenthesis // transforms the tagname into a tag identifier. If the tag is new, we insert @@ -684,9 +693,7 @@ int XMLTree::NewOpenTag(unsigned char *tagname) TagName[i] = (unsigned char *)malloc(sizeof(unsigned char)*(strlen((const char *)tagname)+1)); strcpy((char *)TagName[i], (const char *)tagname); } - - tags_aux = (TagType *)realloc(tags_aux, sizeof(TagType)*(npar + 1)); - + tags_aux = (TagType *) realloc(tags_aux, sizeof(TagType)*(npar + 1)); if (!tags_aux) { fprintf(stderr, "Error: not enough memory\n"); return NULLT; @@ -714,7 +721,11 @@ int XMLTree::NewClosingTag(unsigned char *tagname) } // inserts a new closing parentheses in the bit sequence - par_aux = (pb *)realloc(par_aux, sizeof(pb)*(1+npar/(8*sizeof(pb)))); + if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis + par_aux = (pb *)realloc(par_aux, sizeof(pb)*2*parArraySize); + parArraySize *= 2; + } + if (!par_aux) { fprintf(stderr, "Error: not enough memory\n"); return NULLT;