Added caching of TextCollection
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 16 Feb 2009 01:05:14 +0000 (01:05 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Mon, 16 Feb 2009 01:05:14 +0000 (01:05 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@180 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h

index 4ddec01..cdfe952 100644 (file)
@@ -105,7 +105,15 @@ void XMLTree::Save(unsigned char *filename)
     // stores the texts   \r
     if (!disable_tc)\r
       Text->Save(fp);\r
-\r
+    if (!disable_tc){\r
+    int st = CachedText.size();\r
+    ufwrite(&st, sizeof(int),1,fp);\r
+    for (int i = 0; i< CachedText.size(); ++i){\r
+      st = CachedText.at(i).size();\r
+      ufwrite(&st, sizeof(int),1,fp);\r
+      ufwrite(CachedText.at(i).c_str(),sizeof(char),(1+strlen(CachedText.at(i).c_str())),fp);\r
+    };\r
+    };\r
     fclose(fp);\r
 \r
  }\r
@@ -192,11 +200,27 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text)
     if (!XML_Tree->disable_tc){\r
       XML_Tree->Text = TextCollection::InitTextCollection(sample_rate_text);\r
       XML_Tree->Text->Load(fp,sample_rate_text);\r
+      int sst;\r
+      int st;\r
+      ufread(&sst, sizeof(int),1,fp);\r
+      for (int i=0;i<sst;i++){\r
+       ufread(&st, sizeof(int),1,fp);\r
+       char* str = (char*) malloc(sizeof(char)*st+1);\r
+       ufread(str,sizeof(char),st+1,fp);\r
+       string cppstr = str;\r
+       XML_Tree->CachedText.push_back(cppstr);\r
+       free(str);\r
+      };\r
+\r
     }\r
     else\r
       XML_Tree->Text = NULL;\r
 \r
     s_text = ftell(fp) - s_text;\r
+\r
+    \r
+\r
+\r
     fclose(fp);\r
 \r
     std::cerr << "Tree part is " << s_tree/1024 << " Kbytes,\n"\r
@@ -842,7 +866,7 @@ int XMLTree::NewOpenTag(unsigned char *tagname)
     tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags\r
     \r
     npar++;\r
-\r
+    \r
     return 1;\r
     \r
  }\r
@@ -915,6 +939,8 @@ int XMLTree::NewText(unsigned char *s)
     }\r
     \r
     Text->InsertText(s);\r
+    string cpps = (char*) s;\r
+    CachedText.push_back(cpps); \r
     \r
     return 1; // success\r
  }\r
index a00487a..67ffd6e 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -87,6 +87,8 @@ class XMLTree {
 \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
@@ -390,6 +392,10 @@ public:
    uchar* GetText(DocID d) {\r
       return Text->GetText(d);\r
    }\r
+\r
+   uchar* GetCachedText(DocID d) {\r
+     return (uchar*) (CachedText.at(d).c_str());\r
+   }\r
    \r
    TextCollection *getTextCollection() {\r
       return Text;\r