X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.h;h=d446ab122d2cd37cd0ef9b24c1d66e18e482008b;hb=3c8f8af6704ca98b36b503878058aa0619806dad;hp=759aff83251fe7b820c22bbb6fe836a8d8891a39;hpb=2220c6ca1fb8ebefd48d6f5d9a6be3afc7325da5;p=SXSI%2FXMLTree.git diff --git a/XMLTree.h b/XMLTree.h index 759aff8..d446ab1 100644 --- a/XMLTree.h +++ b/XMLTree.h @@ -26,6 +26,7 @@ #include #include +//KIM : OJO //clash between TextCollection/Tools.h and libcds/includes/basics.h #undef W #undef WW @@ -61,6 +62,13 @@ typedef struct { } range; +//KIM : OJO +// I know this class implements the working draft that we have but the logics seem flawed here... +// We should have two classes. One XMLTreeBuilder and one XMLTree. +// XMLTreeBuilder would have OpenDocument, NewOpenTag,... and CloseDocument would return an XMLTree +// XMLTree would have only an initialized structure. If find it really ugly to check (!finished) or (!initialized) +// in every function (FirstChild....). + class XMLTree { /** Balanced parentheses representation of the tree */ bp *Par; @@ -79,6 +87,8 @@ class XMLTree { /** The texts in the XML document */ TextCollection *Text; + /** The texts in the XML document (cached for faster display) */ + vector CachedText; /** Flag indicating whether the whole data structure has been constructed or * not. If the value is true, you cannot add more texts, nodes, etc. */ @@ -96,7 +106,17 @@ class XMLTree { int parArraySize; int ntagnames; unsigned int *empty_texts_aux; + + // KIM : OJO + // I added those two. The TagName array should always contains two special tags + // <@> for attributes and <$> for PCDATA. + // <$> can never be in a document (since we handle the text differently) + // but <@> can be returned by the parser. This boolean is needed for the construction + // of the Tag bitmap to know if <@> must be taken into account or not bool found_attributes; + + // KIM : OJO + // Allows to disable the TextCollection for benchmarkin purposes bool disable_tc; public: @@ -184,6 +204,10 @@ public: * is none. */ treeNode TaggedDesc(treeNode x, TagType tag); + /** TaggedNext(x,tag): returns the first node tagged tag with larger + * preorder than x. Returns NULT if there is none. */ + treeNode TaggedNext(treeNode x, TagType tag); + /** TaggedPrec(x,tag): returns the first node tagged tag with smaller * preorder than x and not an ancestor of x. Returns NULLT if there * is none. */ @@ -193,7 +217,14 @@ public: * preorder than x and not in the subtree of x. Returns NULLT if there * is none. */ treeNode TaggedFoll(treeNode x, TagType tag); - + + /** TaggedFollowingSibling(x,tag) */ + treeNode TaggedFollowingSibling(treeNode x, TagType tag); + + /** TaggedAncestor(x, tag): returns the closest ancestor of x tagged + * tag. Return NULLT is there is none. */ + treeNode TaggedAncestor(treeNode x, TagType tag); + /** PrevText(x): returns the document identifier of the text to the left of * node x, or NULLT if x is the root node. */ DocID PrevText(treeNode x); @@ -226,6 +257,7 @@ public: * (i.e. everything is considered an empty text *) * Returns a non-zero value upon success, NULLT in case of * error. */ + int OpenDocument(bool empty_texts, int sample_rate_text, bool dtc); /** CloseDocument(): finishes the construction of the data structure for @@ -265,6 +297,19 @@ public: unsigned char *GetTagName(TagType tagid); + // OJO + /** GetTagName(tagid): returns the tag name of a given tag identifier. + * The result is just a reference and should not be freed by the caller. + */ + const unsigned char *GetTagNameByRef(TagType tagid); + + //OJO + /** RegisterTag adds a new tag to the tag collection this is needed + * if the query contains a tag which is not in the document, we need + * to give this new tag a fresh id and store it somewhere. A logical + * choice is here. + * We might want to use a hashtable instead of an array though. + */ TagType RegisterTag(unsigned char *tagname); bool EmptyText(DocID i) { @@ -354,6 +399,10 @@ public: uchar* GetText(DocID d) { return Text->GetText(d); } + + uchar* GetCachedText(DocID d) { + return (uchar*) (CachedText.at(d).c_str()); + } TextCollection *getTextCollection() { return Text;