Jouni's Incremental BWT integrated into TextCollection
authornvalimak <nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 23 Mar 2009 15:33:35 +0000 (15:33 +0000)
committernvalimak <nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 23 Mar 2009 15:33:35 +0000 (15:33 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@272 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h
makefile

index 8f8739d..70cf4b7 100644 (file)
@@ -223,8 +223,7 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text)
 \r
     // loads the texts\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
+      XML_Tree->Text = TextCollection::Load(fp,sample_rate_text);\r
       int sst;\r
       int st;\r
       ufread(&sst, sizeof(int),1,fp);\r
@@ -284,7 +283,9 @@ XMLTree::~XMLTree()
     Tags = NULL;\r
 \r
     //Text->~TextCollection();\r
-    delete Text;\r
+    delete TextBuilder; \r
+    TextBuilder = NULL;\r
+    delete Text; \r
     Text = NULL;\r
 \r
     initialized = false;\r
@@ -1013,9 +1014,11 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text,bool dtc)
     if (!indexing_empty_texts) \r
       empty_texts_aux = (unsigned int *)umalloc(sizeof(unsigned int));\r
        \r
-    \r
-    \r
-    Text = TextCollection::InitTextCollection((unsigned)sample_rate_text);\r
+    if (disable_tc)\r
+        TextBuilder = 0;\r
+    else \r
+        TextBuilder = new TextCollectionBuilder((unsigned)sample_rate_text);\r
+    Text = 0;\r
     \r
     return 1;  // indicates success in the initialization of the data structure\r
  }\r
@@ -1073,10 +1076,16 @@ int XMLTree::CloseDocument()
     //delete ssb;\r
 \r
     \r
-               // makes the text collection static\r
+    // makes the text collection static\r
     if (!disable_tc)\r
-      Text->MakeStatic();\r
-    \r
+    {\r
+        assert(Text = 0);\r
+        assert(TextBuilder != 0);\r
+        Text = TextBuilder->InitTextCollection();\r
+        delete TextBuilder;\r
+        TextBuilder = 0;\r
+    }\r
+\r
     // creates the data structure marking the non-empty texts (just in the case it is necessary)\r
     if (!indexing_empty_texts)  {\r
        EBVector = new static_bitsequence_rrr02((uint *)empty_texts_aux,(ulong)npar,(uint)32);\r
@@ -1214,7 +1223,7 @@ int XMLTree::NewText(unsigned char *s)
               bitset(empty_texts_aux, npar-1);  // marks the non-empty text with a 1 in the bit vector\r
     }\r
     \r
-    Text->InsertText(s);\r
+    TextBuilder->InsertText(s);\r
     string cpps = (char*) s;\r
     CachedText.push_back(cpps); \r
     \r
@@ -1239,7 +1248,7 @@ int XMLTree::NewEmptyText()
        \r
        bitclean(empty_texts_aux, npar-1);  // marks the empty text with a 0 in the bit vector\r
     }\r
-    else Text->InsertText(&c); // we insert the empty text just in case we index all the texts\r
+    else TextBuilder->InsertText(&c); // we insert the empty text just in case we index all the texts\r
     \r
     return 1; // success    \r
  }\r
index 80173a4..9b79ae3 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -21,7 +21,7 @@
 \r
 #ifndef XMLTREE_H_\r
 #define XMLTREE_H_\r
-#include "TextCollection/TextCollection.h"\r
+#include "TextCollection/TextCollectionBuilder.h"\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <cstring>\r
@@ -37,6 +37,7 @@
 #include <alphabet_mapper.h>\r
 #include <static_sequence.h>\r
 using SXSI::TextCollection;\r
+using SXSI::TextCollectionBuilder;\r
 \r
 \r
 // this constant is used to efficiently compute the child operation in the tree\r
@@ -88,7 +89,9 @@ class XMLTree {
         uint tags_blen, tags_len;\r
 \r
    /** The texts in the XML document */\r
+   TextCollectionBuilder *TextBuilder;\r
    TextCollection *Text;\r
+\r
    /** The texts in the XML document (cached for faster display) */\r
    vector<string> CachedText;\r
    \r
@@ -125,7 +128,7 @@ public:
         void print_stats();\r
 \r
    /** Data structure constructor */\r
-   XMLTree() {finished = false; initialized = false;}; \r
+   XMLTree() {finished = false; initialized = false; Text = 0; TextBuilder = 0; }; \r
  \r
    /** Data structure destructor */\r
    ~XMLTree();\r
@@ -331,7 +334,7 @@ public:
    TagType RegisterTag(unsigned char *tagname);\r
 \r
    bool EmptyText(DocID i) {\r
-      return Text->EmptyText(i);\r
+       return Text->EmptyText(i);\r
    }\r
    /** Prefix(s): search for texts prefixed by string s. */\r
    TextCollection::document_result Prefix(uchar const *s) {\r
@@ -420,7 +423,7 @@ public:
    /** GetText(d): returns the text corresponding to document with\r
     * id d. */\r
    uchar* GetText(DocID d) {\r
-      return Text->GetText(d);\r
+       return Text->GetText(d);\r
    }\r
 \r
    uchar* GetCachedText(DocID d) {\r
index 4f06f3b..e1705ef 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,7 +1,7 @@
 FLAGS =-std=c++0x -O3 -I./libcds/includes/\r
 \r
 OBJECTS=libcds/lib/libcds.a\r
-OBJECTS_TC= TextCollection/TextCollection.o TextCollection/CSA.o TextCollection/Tools.o TextCollection/BitRank.o TextCollection/bittree.o TextCollection/rbtree.o TextCollection/dynFMI.o TextCollection/RLWaveletTree.o TextCollection/GapEncode.o TextCollection/BSGAP.o\r
+OBJECTS_TC= TextCollection/TextCollection.o TextCollection/TextCollectionBuilder.o TextCollection/TCImplementation.o TextCollection/Tools.o TextCollection/BitRank.o TextCollection/BSGAP.o TextCollection/incbwt/rlcsa.a\r
 \r
 all: libcds text_collection XMLTree\r
 \r