X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.cpp;h=9057e31af5f10181b78f29d1c7ca30841c9e0979;hb=6a9117a97674437c9fe00b099c40ccb61d45d704;hp=95546fd0644aa38c03d3239554a698255a7ab955;hpb=3b0e5683fd88917737d9adb681a13bb0b2160ce5;p=SXSI%2FXMLTree.git diff --git a/XMLTree.cpp b/XMLTree.cpp index 95546fd..9057e31 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -211,6 +211,14 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text) s_tree+=2*sizeof(uint)+sizeof(uint)*uint_len(XML_Tree->tags_blen,XML_Tree->tags_len); s_tree+= XML_Tree->Tags->size(); + /// FIXME:UGLY tests! + /*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;*/ + /// End ugly tests + s_text = ftell(fp); // loads the texts @@ -753,6 +761,24 @@ treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) else return tagpos2node(s); } +// TaggedFoll(x,tag): returns the first node tagged tag with larger preorder than x and not in +// the subtree of x. Returns NULLT if there is none. +treeNode XMLTree::TaggedFollBelow(treeNode x, TagType tag, treeNode root) + { + + int r, s; + int lim = node2tagpos(find_close(Par,root)); + if (x ==NULLT || x == Root()) + return NULLT; + + r = (int) Tags->rank(tag,find_close(Par,x)); + s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag. + if (s==-1 || s >= lim) + return NULLT; + else + return tagpos2node(s); + } + // TaggedFollowingSibling(x,tag): returns the first node tagged tag with larger preorder than x and not in // the subtree of x. Returns NULLT if there is none. @@ -1012,10 +1038,6 @@ int XMLTree::CloseDocument() Par = (bp *)umalloc(sizeof(bp)); bp_construct(Par, npar, par_aux, OPT_DEGREE|0); // creates structure for tags - //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); - // 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 @@ -1023,25 +1045,34 @@ int XMLTree::CloseDocument() for(uint i=0;i<(uint)npar-1;i++) max_tag = max(max_tag,tags_aux[i]); max_tag++; - int ntagsize = found_attributes ? 2*ntagnames-1 : 2*ntagnames - 2; 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; + //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); static_bitsequence_builder * bmb = new static_bitsequence_builder_brw32(20); alphabet_mapper *am = new alphabet_mapper_none(); wt_coder * wc = new wt_coder_huff((uint*)tags_aux,npar,am); Tags = new static_sequence_wvtree((uint*)tags_aux,npar,wc ,bmb, am); - //Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,ntagsize, bmb, ssb); + //Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar,ntagsize, bmb, ssb); + + cout << "Tags test: " << Tags->test((uint*)tags_aux,npar) << endl; + tags_blen = bits(max_tag); tags_len = (uint)npar; tags_fix = new uint[uint_len(tags_blen,tags_len)]; - for(uint i=0;i<(uint)npar-1;i++) + for(uint i=0;i<(uint)npar;i++) set_field(tags_fix,tags_blen,i,tags_aux[i]); delete bmb; //delete pmb; //delete ssb; - // makes the text collection static + + + // makes the text collection static if (!disable_tc) Text->MakeStatic();