X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=fe01896d4ca75c93ffdf83121b9d0ba1a42efca0;hb=add1a8a0b8a7ca05bb099ec38a60f3c52b9dfd71;hp=92360a432535065f46769245eadee9f98515c005;hpb=a9846746dc7a55764591fcc273fd48c6049df962;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index 92360a4..fe01896 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -311,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. @@ -345,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); } @@ -570,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; @@ -588,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)); @@ -629,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; @@ -675,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)); @@ -842,4 +878,19 @@ unsigned char *XMLTree::GetTagName(TagType tagid) } - +TagType XMLTree::RegisterTag(unsigned char *tagname) +{ + if (!finished) + return NULLT; + + + TagType id = XMLTree::GetTagId(tagname); + if (id == NULLT){ + id = ntagnames; + ntagnames = ntagnames + 1; + TagName = (unsigned char **) realloc(TagName,ntagnames*(sizeof(unsigned char*))); + strcpy((char*)TagName[id], (const char *)tagname); + }; + + return id; +}