Approx pattern matching functions
[SXSI/XMLTree.git] / XMLTree.h
index 6a722f9..ee44d32 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -40,7 +40,7 @@
 #include <static_sequence.h>\r
 using SXSI::TextCollection;\r
 using SXSI::TextCollectionBuilder;\r
-\r
+using SXSI::TextStorage;\r
 \r
 // this constant is used to efficiently compute the child operation in the tree\r
 #define OPTD 10\r
@@ -118,9 +118,6 @@ class XMLTree {
    /** The texts in the XML document */\r
    TextCollection *Text;\r
 \r
-   /** The texts in the XML document (cached for faster display) */\r
-   vector<string> *CachedText;\r
-\r
    // Allows to disable the TextCollection for benchmarkin purposes\r
    bool disable_tc;\r
    \r
@@ -130,7 +127,7 @@ class XMLTree {
 \r
    // non const pointer are freed by this method.\r
   XMLTree( pb * const par, uint npar,  vector<string> * const TN,  TagIdMap * const tim, uint *empty_texts_bmp, TagType *tags,\r
-          TextCollection * const TC, vector<string> * const CT, bool dis_tc);\r
+          TextCollection * const TC, bool dis_tc);\r
 \r
 public: \r
    /** Data structure destructor */\r
@@ -328,6 +325,20 @@ public:
    TextCollection::document_result LessThan(uchar const *s) {\r
       return Text->LessThan(s);\r
    }\r
+\r
+   /** KMismatches (s): returns document identifiers for the texts that\r
+    * contain occurrence of string s with at most K mismatches. */\r
+   TextCollection::document_result KMismatches(uchar const *s, unsigned K) {\r
+       return Text->KMismatches(s, K);\r
+   }\r
+\r
+   /** KErrors (s): returns document identifiers for the texts that\r
+    * contain occurrence of string s with at most K errors. \r
+    * The accepted "errors" are insertions, deletions and mutations of chars.\r
+    */\r
+   TextCollection::document_result KErrors(uchar const *s, unsigned K) {\r
+       return Text->KErrors(s, K);\r
+   }\r
    \r
    /** IsPrefix(x): returns true if there is a text prefixed by string s. */\r
    bool IsPrefix(uchar const *s) {\r
@@ -388,25 +399,35 @@ public:
    }\r
    \r
    /** GetText(d): returns the text corresponding to document with\r
-    * id d. */\r
-   uchar* GetText(DocID d) {\r
-     uchar * s = Text->GetText(d);\r
-     return (s[0] == 1 ? (uchar*)"" : s);\r
+    * id d. \r
+    *\r
+    * Implementation of GetText() may or may NOT \r
+    * require you to free() the pointer that is returned.\r
+    * Call DeleteText() for each pointer returned by GetText()\r
+    * to avoid possible memory leaks.\r
+    */\r
+   uchar* GetText(DocID d) const {\r
+     return Text->GetText(d);\r
    }\r
 \r
-   /** GetText(i, j): returns the texts corresponding to documents with\r
-    * ids i, i+1, ..., j. Texts are separated by '\0' character.  */\r
-   uchar* GetText(DocID i, DocID j) {\r
-     uchar * s = Text->GetText(i, j);\r
-     return (s[0] == 1 ? (uchar*)"" : s);\r
+   /**\r
+    * Free the pointer returned by GetText().\r
+    */\r
+   void DeleteText(uchar *text) const {\r
+       Text->DeleteText(text);\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
+   /** GetText(i, j): returns the texts corresponding to documents with\r
+    * ids i, i+1, ..., j. Texts are separated by '\0' character.  \r
+    *\r
+    * Call DeleteText() for each pointer returned by GetText()\r
+    * to avoid possible memory leaks.\r
+    */\r
+   uchar* GetText(DocID i, DocID j) const {\r
+     return Text->GetText(i, j);\r
    }\r
-   \r
+\r
+\r
    TextCollection *getTextCollection() {\r
       return Text;\r
    }\r