X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=fe01896d4ca75c93ffdf83121b9d0ba1a42efca0;hb=add1a8a0b8a7ca05bb099ec38a60f3c52b9dfd71;hp=22ba4bb9a9e993dd7cdb4c48fbdb9987acd9f75a;hpb=184fd5131d257a334c29b0e55b1240fb29dc796b;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index 22ba4bb..fe01896 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -574,9 +574,10 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text) { initialized = true; finished = false; + found_attributes = false; npar = 0; parArraySize = 1; - ntagnames = 0; + ntagnames = 2; indexing_empty_texts = empty_texts; @@ -592,7 +593,28 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text) return NULLT; } - TagName = NULL; + TagName = (unsigned char **) malloc(2*sizeof(unsigned char*)); + if (!TagName){ + fprintf(stderr, "Error: not enough memory\n"); + return NULLT; + } + + TagName[0] = (unsigned char *) malloc(4*sizeof(unsigned char)); + strcpy((char *) TagName[0], "<@>"); + + if (!TagName[0]){ + fprintf(stderr, "Error: not enough memory\n"); + return NULLT; + } + + TagName[1] = (unsigned char *) malloc(4*sizeof(unsigned char)); + if (!TagName[1]){ + fprintf(stderr, "Error: not enough memory\n"); + return NULLT; + } + + strcpy((char *) TagName[1], "<$>"); + if (!indexing_empty_texts) { empty_texts_aux = (unsigned int *)malloc(sizeof(unsigned int)); @@ -633,7 +655,12 @@ int XMLTree::CloseDocument() 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); + + // If we found an attribute then "<@>" is present in the tree + // if we didn't then it is not. "<$>" is never present in the tree + int ntagsize = found_attributes ? 2*ntagnames-1 : 2*ntagnames - 2; + + Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,ntagsize, bmb, ssb); delete bmb; delete pmb; @@ -679,8 +706,13 @@ int XMLTree::NewOpenTag(unsigned char *tagname) // transforms the tagname into a tag identifier. If the tag is new, we insert // it in the table. for (i=0; i") was called + if (i==0) + found_attributes=true; + if (i==ntagnames) { // the tag is a new one, then we insert it TagName = (unsigned char **)realloc(TagName, sizeof(char *)*(ntagnames+1));