Quick fix for WT construction space
[SXSI/XMLTree.git] / XMLTree.h
index c054b01..2e9e222 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <cstring>\r
+\r
+//KIM : OJO\r
+//clash between TextCollection/Tools.h and libcds/includes/basics.h\r
+#undef W\r
+#undef WW\r
+#undef Wminusone\r
+\r
 #include "bp.h"\r
 #include <static_bitsequence.h>\r
 #include <alphabet_mapper.h>\r
@@ -55,6 +62,13 @@ typedef struct {
 } range;\r
 \r
 \r
+//KIM : OJO\r
+// I know this class implements the working draft that we have but the logics seem flawed here...\r
+// We should have two classes. One XMLTreeBuilder and one XMLTree.\r
+// XMLTreeBuilder would have OpenDocument, NewOpenTag,... and CloseDocument would return an XMLTree\r
+// XMLTree would have only an initialized structure. If find it really ugly to check (!finished) or (!initialized)\r
+// in every function (FirstChild....).\r
+\r
 class XMLTree {\r
    /** Balanced parentheses representation of the tree */\r
    bp *Par;\r
@@ -70,9 +84,13 @@ class XMLTree {
                      \r
    /** Tag sequence represented with a data structure for rank and select */\r
    static_sequence *Tags;\r
+        uint * tags_fix;\r
+        uint tags_blen, tags_len;\r
 \r
    /** The texts in the XML document */\r
    TextCollection *Text;\r
+   /** The texts in the XML document (cached for faster display) */\r
+   vector<string> CachedText;\r
    \r
    /** Flag indicating whether the whole data structure has been constructed or \r
     * not. If the value is true, you cannot add more texts, nodes, etc. */\r
@@ -90,10 +108,21 @@ class XMLTree {
    int parArraySize;\r
    int ntagnames;\r
    unsigned int *empty_texts_aux;\r
+\r
+   // KIM : OJO\r
+   // I added those two. The TagName array should always contains two special tags\r
+   // <@> for attributes and <$> for PCDATA.\r
+   // <$> can never be in a document (since we handle the text differently)\r
+   // but <@> can be returned by the parser. This boolean is needed for the construction\r
+   // of the Tag bitmap to know if <@> must be taken into account or not\r
    bool found_attributes;\r
+\r
+   // KIM : OJO\r
+   // Allows to disable the TextCollection for benchmarkin purposes\r
    bool disable_tc;\r
    \r
 public:\r
+        void print_stats();\r
 \r
    /** Data structure constructor */\r
    XMLTree() {finished = false; initialized = false;}; \r
@@ -178,6 +207,10 @@ public:
     * is none. */\r
    treeNode TaggedDesc(treeNode x, TagType tag);\r
 \r
+   /** TaggedNext(x,tag): returns the first node tagged tag with larger \r
+    * preorder than x. Returns NULT if there is none. */\r
+   treeNode TaggedNext(treeNode x, TagType tag);\r
+\r
    /** TaggedPrec(x,tag): returns the first node tagged tag with smaller \r
     * preorder than x and not an ancestor of x. Returns NULLT if there \r
     * is none. */\r
@@ -187,7 +220,14 @@ public:
     * preorder than x and not in the subtree of x. Returns NULLT if there \r
     * is none. */\r
    treeNode TaggedFoll(treeNode x, TagType tag);\r
-   \r
+  \r
+   /** TaggedFollowingSibling(x,tag) */\r
+   treeNode TaggedFollowingSibling(treeNode x, TagType tag);\r
+\r
+   /** TaggedAncestor(x, tag): returns the closest ancestor of x tagged \r
+     * tag. Return NULLT is there is none. */\r
+   treeNode TaggedAncestor(treeNode x, TagType tag);\r
\r
    /** PrevText(x): returns the document identifier of the text to the left of \r
     * node x, or NULLT if x is the root node. */\r
    DocID PrevText(treeNode x);\r
@@ -220,6 +260,7 @@ public:
     * (i.e. everything is considered an empty text *)\r
     * Returns a non-zero value upon success, NULLT in case of \r
     * error. */\r
+\r
    int OpenDocument(bool empty_texts, int sample_rate_text, bool dtc);\r
 \r
    /** CloseDocument(): finishes the construction of the data structure for \r
@@ -259,6 +300,19 @@ public:
    unsigned char *GetTagName(TagType tagid);\r
 \r
 \r
+   // OJO\r
+   /** GetTagName(tagid): returns the tag name of a given tag identifier.     \r
+    *  The result is just a reference and should not be freed by the caller.\r
+    */\r
+   const unsigned char *GetTagNameByRef(TagType tagid);\r
+\r
+   //OJO\r
+   /** RegisterTag adds a new tag to the tag collection this is needed\r
+    * if the query contains a tag which is not in the document, we need\r
+    * to give this new tag a fresh id and store it somewhere. A logical\r
+    * choice is here.\r
+    * We might want to use a hashtable instead of an array though.\r
+    */\r
    TagType RegisterTag(unsigned char *tagname);\r
 \r
    bool EmptyText(DocID i) {\r
@@ -348,6 +402,12 @@ public:
    uchar* GetText(DocID d) {\r
       return Text->GetText(d);\r
    }\r
+\r
+   uchar* GetCachedText(DocID d) {\r
+     uchar * str = (uchar*) calloc(sizeof(char),(CachedText.at(d).size() + 1));\r
+     strcpy((char*) str,(const char*) CachedText.at(d).c_str());\r
+     return (uchar*) (str);\r
+   }\r
    \r
    TextCollection *getTextCollection() {\r
       return Text;\r