New (faster) representation for tags added; faster construction of parentheses
[SXSI/XMLTree.git] / XMLTree.cpp
index 7d0c5e3..92360a4 100644 (file)
@@ -101,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);\r
 \r
     // loads the tags\r
-    XML_Tree->Tags = static_sequence_wvtree::load(fp);\r
+    XML_Tree->Tags = static_sequence::load(fp);\r
 \r
     // loads the texts   \r
     XML_Tree->Text->Load(fp,sample_rate_text);\r
@@ -126,16 +126,16 @@ XMLTree::~XMLTree()
     free(TagName);\r
 \r
     if (!indexing_empty_texts) {\r
-       EBVector->~static_bitsequence_rrr02();\r
+       //EBVector->~static_bitsequence_rrr02();\r
        delete EBVector;\r
        EBVector = NULL;\r
     }\r
 \r
-    Tags->~static_sequence_wvtree();\r
+    //Tags->~static_sequence_wvtree();\r
     delete Tags;\r
     Tags = NULL;\r
 \r
-    Text->~TextCollection();\r
+    //Text->~TextCollection();\r
     delete Text;\r
     Text = NULL;\r
 \r
@@ -571,11 +571,12 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text)
     initialized = true;\r
     finished = false;\r
     npar = 0;\r
-    ntagnames = 0;\r
-    \r
+    parArraySize = 1;\r
+    ntagnames = 0;    \r
\r
     indexing_empty_texts = empty_texts;\r
     \r
-    par_aux = (pb *)malloc(sizeof(pb));\r
+    par_aux = (pb *)malloc(sizeof(pb)*parArraySize);\r
     if (!par_aux) {\r
        fprintf(stderr, "Error: not enough memory\n");\r
        return NULLT;\r
@@ -621,14 +622,18 @@ int XMLTree::CloseDocument()
     }\r
     \r
     // creates the data structure for the tree topology\r
-    Par = (bp *)malloc(sizeof(bp));      \r
+    Par = (bp *)malloc(sizeof(bp));\r
     bp_construct(Par, npar, par_aux, OPT_DEGREE|0);    \r
     // creates structure for tags\r
-    alphabet_mapper * am = new alphabet_mapper_none();\r
-    static_bitsequence_builder * bmb = new static_bitsequence_builder_rrr02(32); \r
-    wt_coder * wtc = new wt_coder_huff((uint *)tags_aux,npar-1,am);\r
-    Tags = new static_sequence_wvtree((uint *) tags_aux, (uint) npar-1, wtc, bmb, am);\r
+    static_bitsequence_builder * bmb = new static_bitsequence_builder_brw32(20);\r
+    static_permutation_builder * pmb = new static_permutation_builder_mrrr(PERM_SAMPLE, bmb);\r
+    static_sequence_builder * ssb = new static_sequence_builder_gmr_chunk(bmb, pmb);\r
 \r
+    Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,2*ntagnames, bmb, ssb);\r
+    \r
+    delete bmb;\r
+    delete pmb;\r
+    delete ssb;\r
     // makes the text collection static\r
     Text->MakeStatic();\r
     \r
@@ -655,7 +660,11 @@ int XMLTree::NewOpenTag(unsigned char *tagname)
     }\r
     \r
     // inserts a new opening parentheses in the bit sequence\r
-    par_aux = (pb *)realloc(par_aux, sizeof(pb)*(1+npar/(8*sizeof(pb))));\r
+    if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis\r
+       par_aux = (pb *)realloc(par_aux, sizeof(pb)*2*parArraySize);\r
+       parArraySize *= 2;\r
+    }\r
+    \r
     if (!par_aux) {\r
        fprintf(stderr, "Error: not enough memory\n");\r
        return NULLT;    \r
@@ -708,7 +717,11 @@ int XMLTree::NewClosingTag(unsigned char *tagname)
     }\r
     \r
     // inserts a new closing parentheses in the bit sequence\r
-    par_aux = (pb *)realloc(par_aux, sizeof(pb)*(1+npar/(8*sizeof(pb))));\r
+    if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis\r
+       par_aux = (pb *)realloc(par_aux, sizeof(pb)*2*parArraySize);\r
+       parArraySize *= 2;\r
+    }\r
+    \r
     if (!par_aux) {\r
        fprintf(stderr, "Error: not enough memory\n");\r
        return NULLT;    \r