X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=249143cfbe456ffc8d78d10262f82167baa773dd;hb=69d191f9549b65e692b38bfceecc86fbcde474ad;hp=2a1ca71b035d4b37c3492f8b583e8dd204f137f6;hpb=4b998a9c4982a8971b2997adbad9fd654de4b634;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index 2a1ca71..249143c 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -212,19 +212,18 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text) s_tree+= XML_Tree->Tags->size(); /// FIXME:UGLY tests! - /*uint * seq = new uint[XML_Tree->tags_len]; + uint * seq = new uint[XML_Tree->tags_len]; for(uint i=0;itags_len;i++) seq[i] = get_field(XML_Tree->tags_fix,XML_Tree->tags_blen,i); cout << "Tags test: " << XML_Tree->Tags->test(seq,XML_Tree->tags_len) << endl; - delete [] seq;*/ + delete [] seq; /// End ugly tests s_text = ftell(fp); // loads the texts if (!XML_Tree->disable_tc){ - XML_Tree->Text = TextCollection::InitTextCollection(sample_rate_text); - XML_Tree->Text->Load(fp,sample_rate_text); + XML_Tree->Text = TextCollection::Load(fp,sample_rate_text); int sst; int st; ufread(&sst, sizeof(int),1,fp); @@ -284,7 +283,9 @@ XMLTree::~XMLTree() Tags = NULL; //Text->~TextCollection(); - delete Text; + delete TextBuilder; + TextBuilder = NULL; + delete Text; Text = NULL; initialized = false; @@ -356,7 +357,9 @@ bool XMLTree::IsChild(treeNode x, treeNode y) if (!is_ancestor(Par, x, y)) return false; return depth(Par, x) == (depth(Par, y) + 1); } - +bool XMLTree::IsFirstChild(treeNode x){ + return ((x != NULLT)&&(x==Root() || prev_sibling(Par,x) == NULLT)); +} // NumChildren(x): number of children of node x. Constant time with the data structure // of Sadakane. int XMLTree::NumChildren(treeNode x) @@ -498,6 +501,14 @@ treeNode XMLTree::FirstChild(treeNode x) return first_child(Par, x); } +treeNode XMLTree::LastChild(treeNode x) +{ + if (x == Root() || isleaf(Par,x) || x == NULLT) + return x; + else + return find_open(Par,find_close(Par,parent(Par,x))-1); +} + // NextSibling(x): returns the next sibling of node x, assuming it exists. treeNode XMLTree::NextSibling(treeNode x) { @@ -1013,9 +1024,11 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc) if (!indexing_empty_texts) empty_texts_aux = (unsigned int *)umalloc(sizeof(unsigned int)); - - - Text = TextCollection::InitTextCollection((unsigned)sample_rate_text); + if (disable_tc) + TextBuilder = 0; + else + TextBuilder = new TextCollectionBuilder((unsigned)sample_rate_text); + Text = 0; return 1; // indicates success in the initialization of the data structure } @@ -1044,9 +1057,9 @@ int XMLTree::CloseDocument() uint max_tag = 0; for(uint i=0;i<(uint)npar-1;i++) max_tag = max(max_tag,tags_aux[i]); - max_tag++; - tags_aux = (TagType *) urealloc(tags_aux, sizeof(TagType)*(npar + 1)); - tags_aux[npar++] = max_tag; + //max_tag++; + //tags_aux = (TagType *) urealloc(tags_aux, sizeof(TagType)*(npar + 1)); + //tags_aux[npar++] = max_tag; //int ntagsize = found_attributes ? 2*ntagnames-1 : 2*ntagnames - 2; int ntagsize = 2*ntagnames + 2; @@ -1073,10 +1086,16 @@ int XMLTree::CloseDocument() //delete ssb; - // makes the text collection static + // makes the text collection static if (!disable_tc) - Text->MakeStatic(); - + { + assert(Text == 0); + assert(TextBuilder != 0); + Text = TextBuilder->InitTextCollection(); + delete TextBuilder; + TextBuilder = 0; + } + // creates the data structure marking the non-empty texts (just in the case it is necessary) if (!indexing_empty_texts) { EBVector = new static_bitsequence_rrr02((uint *)empty_texts_aux,(ulong)npar,(uint)32); @@ -1214,7 +1233,7 @@ int XMLTree::NewText(unsigned char *s) bitset(empty_texts_aux, npar-1); // marks the non-empty text with a 1 in the bit vector } - Text->InsertText(s); + TextBuilder->InsertText(s); string cpps = (char*) s; CachedText.push_back(cpps); @@ -1239,7 +1258,7 @@ int XMLTree::NewEmptyText() bitclean(empty_texts_aux, npar-1); // marks the empty text with a 0 in the bit vector } - else Text->InsertText(&c); // we insert the empty text just in case we index all the texts + else TextBuilder->InsertText(&c); // we insert the empty text just in case we index all the texts return 1; // success } @@ -1253,7 +1272,7 @@ TagType XMLTree::GetTagId(unsigned char *tagname) // this should be changed for more efficient processing for (i=0; i= ntagnames) return NULL; // invalid tag identifier s = (unsigned char *)umalloc((strlen((const char *)TagName[tagid])+1)*sizeof(unsigned char)); strcpy((char *)s, (const char *)TagName[tagid]); @@ -1275,6 +1294,7 @@ unsigned char *XMLTree::GetTagName(TagType tagid) const unsigned char *XMLTree::GetTagNameByRef(TagType tagid) { + if(tagid==(uint)-1) return NULL; if (tagid >= ntagnames) return NULL; // invalid tag identifier return ((const unsigned char*) TagName[tagid]); }