X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=XMLTree.h;h=7c08fcc78ec39faa4f09396260a81f9c67320c21;hb=0f2d33d4ee4291d61750769c2918263c7e485ffa;hp=c0dab2b6155ab6db9af1127c2b2416893849c61d;hpb=143f18091facab1154eb750b6ed530905bfed889;p=SXSI%2FXMLTree.git diff --git a/XMLTree.h b/XMLTree.h index c0dab2b..7c08fcc 100644 --- a/XMLTree.h +++ b/XMLTree.h @@ -25,6 +25,13 @@ #include #include #include + +//KIM : OJO +//clash between TextCollection/Tools.h and libcds/includes/basics.h +#undef W +#undef WW +#undef Wminusone + #include "bp.h" #include #include @@ -37,6 +44,8 @@ using SXSI::TextCollection; #define NULLT -1 +#define PERM_SAMPLE 10 + // sets bit p in e #define bitset(e,p) ((e)[(p)/W] |= (1<<((p)%W))) // cleans bit p in e @@ -53,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; @@ -67,7 +83,7 @@ class XMLTree { static_bitsequence_rrr02 *EBVector; /** Tag sequence represented with a data structure for rank and select */ - static_sequence_wvtree *Tags; + static_sequence *Tags; /** The texts in the XML document */ TextCollection *Text; @@ -85,8 +101,21 @@ class XMLTree { pb *par_aux; TagType *tags_aux; int npar; + 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: @@ -206,14 +235,17 @@ public: /** ParentNode(d): returns the parent node of document identifier d. */ treeNode ParentNode(DocID d); - /** OpenDocument(empty_texts,sample_rate_text): initilizes the construction + /** OpenDocument(empty_texts,sample_rate_text,dtc): initilizes the construction * of the data structure for the XML document. Parameter empty_texts * indicates whether we index empty texts in document or not. Parameter * sample_rate_text indicates the sampling rate for the text searching data * structures (small values get faster searching but a bigger space - * requirement). Returns a non-zero value upon success, NULLT in case of + * requirement). dtc disable the use of the TextCollection + * (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); + + int OpenDocument(bool empty_texts, int sample_rate_text, bool dtc); /** CloseDocument(): finishes the construction of the data structure for * the XML document. Tree and tags are represented in the final form, @@ -251,6 +283,25 @@ public: * Returns NULL in case that the tag identifier is not valid.*/ 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) { + return Text->EmptyText(i); + } /** Prefix(s): search for texts prefixed by string s. */ TextCollection::document_result Prefix(uchar const *s) { return Text->Prefix(s); @@ -333,9 +384,12 @@ public: /** GetText(d): returns the text corresponding to document with * id d. */ uchar* GetText(DocID d) { - Text->GetText(d); + return Text->GetText(d); } + TextCollection *getTextCollection() { + return Text; + } /** Save: saves XML tree data structure to file. */ void Save(unsigned char *filename);