// stores the texts \r
if (!disable_tc)\r
Text->Save(fp);\r
-\r
+ if (!disable_tc){\r
+ int st = CachedText.size();\r
+ ufwrite(&st, sizeof(int),1,fp);\r
+ for (int i = 0; i< CachedText.size(); ++i){\r
+ st = CachedText.at(i).size();\r
+ ufwrite(&st, sizeof(int),1,fp);\r
+ ufwrite(CachedText.at(i).c_str(),sizeof(char),(1+strlen(CachedText.at(i).c_str())),fp);\r
+ };\r
+ };\r
fclose(fp);\r
\r
}\r
if (!XML_Tree->disable_tc){\r
XML_Tree->Text = TextCollection::InitTextCollection(sample_rate_text);\r
XML_Tree->Text->Load(fp,sample_rate_text);\r
+ int sst;\r
+ int st;\r
+ ufread(&sst, sizeof(int),1,fp);\r
+ for (int i=0;i<sst;i++){\r
+ ufread(&st, sizeof(int),1,fp);\r
+ char* str = (char*) malloc(sizeof(char)*st+1);\r
+ ufread(str,sizeof(char),st+1,fp);\r
+ string cppstr = str;\r
+ XML_Tree->CachedText.push_back(cppstr);\r
+ free(str);\r
+ };\r
+\r
}\r
else\r
XML_Tree->Text = NULL;\r
\r
s_text = ftell(fp) - s_text;\r
+\r
+ \r
+\r
+\r
fclose(fp);\r
\r
std::cerr << "Tree part is " << s_tree/1024 << " Kbytes,\n"\r
fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
exit(1);\r
}\r
+ if (x == Root())\r
+ x = first_child(Par,x);\r
+ \r
\r
int s = x + 2*subtree_size(Par, x) - 1;\r
\r
fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
exit(1);\r
}\r
-\r
+ \r
return Tags->access(node2tagpos(x));\r
}\r
\r
\r
int r, s;\r
treeNode y;\r
+ if (isleaf(Par,x))\r
+ return NULLT;\r
+\r
r = (int) Tags->rank(tag, node2tagpos(x));\r
s = (int) Tags->select(tag, r+1);\r
if (s == -1) return NULLT; // there is no such node\r
else return y;\r
}\r
\r
+// TaggedNext(x,tag): returns the first node tagged tag with larger preorder than x \r
+// Returns NULLT if there is none.\r
+treeNode XMLTree::TaggedNext(treeNode x, TagType tag) \r
+ {\r
+ if (!finished) {\r
+ fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+ exit(1);\r
+ }\r
+\r
+ int r, s;\r
+ treeNode y;\r
+ if (x==NULLT)\r
+ return NULLT;\r
+\r
+ r = (int) Tags->rank(tag, node2tagpos(x));\r
+ s = (int) Tags->select(tag, r+1);\r
+ if (s == -1) return NULLT; // there is no such node\r
+ y = tagpos2node(s); // transforms the tag position into a node position \r
+ return (y<=x ? NULLT : y);\r
+ }\r
+\r
+\r
// TaggedPrec(x,tag): returns the first node tagged tag with smaller preorder than x and not an\r
// ancestor of x. Returns NULLT if there is none.\r
treeNode XMLTree::TaggedPrec(treeNode x, TagType tag) \r
return NULLT; // there is no such node \r
}\r
\r
+\r
// TaggedFoll(x,tag): returns the first node tagged tag with larger preorder than x and not in\r
// the subtree of x. Returns NULLT if there is none.\r
-treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) \r
+treeNode XMLTree::TaggedFoll(treeNode x, TagType tag)\r
+ {\r
+ if (!finished) {\r
+ fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+ exit(1);\r
+ }\r
+\r
+ int r, s;\r
+ if (x ==NULLT || x == Root())\r
+ return NULLT;\r
+ \r
+ r = (int) Tags->rank(tag, find_close(Par, x));\r
+ s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag.\r
+ if (s==-1) return NULLT;\r
+ else return tagpos2node(s);\r
+ } \r
+\r
+\r
+// TaggedFollowingSibling(x,tag): returns the first node tagged tag with larger preorder than x and not in\r
+// the subtree of x. Returns NULLT if there is none.\r
+treeNode XMLTree::TaggedFollowingSibling(treeNode x, TagType tag) \r
{\r
if (!finished) {\r
fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
}\r
\r
int r, s;\r
- r = (int) Tags->rank(tag, node2tagpos(next_sibling(Par, x))-1);\r
+ treeNode ns = next_sibling(Par,x);\r
+\r
+ if (x == NULLT || x == Root() || ns == -1)\r
+ return NULLT;\r
+\r
+ r = (int) Tags->rank(tag, node2tagpos(ns)-1);\r
s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag.\r
if (s==-1) return NULLT;\r
else return tagpos2node(s);\r
}\r
\r
+\r
+// TaggedAncestor(x, tag): returns the closest ancestor of x tagged tag. Return\r
+// NULLT is there is none.\r
+treeNode XMLTree::TaggedAncestor(treeNode x, TagType tag)\r
+ {\r
+ if (!finished) {\r
+ fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+ exit(1);\r
+ }\r
+ \r
+ if (x == NULLT || x == Root())\r
+ return NULLT;\r
+ \r
+ treeNode s = parent(Par, x), r = Root();\r
+ while (s != r) {\r
+ if (Tags->access(node2tagpos(s)) == tag) return s;\r
+ s = parent(Par, s);\r
+ }\r
+ return NULLT;\r
+ }\r
+\r
+\r
// PrevText(x): returns the document identifier of the text to the left \r
// of node x, or NULLT if x is the root node or the text is empty.\r
// Assumes Doc ids start from 0.\r
tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags\r
\r
npar++;\r
-\r
+ \r
return 1;\r
\r
}\r
parArraySize *= 2;\r
}\r
\r
- setbit(par_aux,npar,CP); // marks a new closing opening parenthesis\r
+ setbit(par_aux,npar,CP); // marks a new closing parenthesis\r
\r
// transforms the tagname into a tag identifier. If the tag is new, we insert\r
// it in the table.\r
for (i=0; i<ntagnames; i++)\r
- if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;\r
+ if ((strcmp((const char *)tagname,(const char *)(TagName[i]+1))==0) && (TagName[i][0]=='/')) break;\r
\r
if (i==ntagnames) { // the tag is a new one, then we insert it\r
TagName = (unsigned char **)urealloc(TagName, sizeof(char *)*(ntagnames+1));\r
\r
- \r
ntagnames++;\r
TagName[i] = (unsigned char *)umalloc(sizeof(char)*(strlen((const char *)tagname)+2));\r
TagName[i][0] = '/';\r
}\r
\r
Text->InsertText(s);\r
+ string cpps = (char*) s;\r
+ CachedText.push_back(cpps); \r
\r
return 1; // success\r
}\r