add compat method for phrase index
authorPeng Wu <alexepico@gmail.com>
Tue, 14 Sep 2010 08:05:05 +0000 (16:05 +0800)
committerPeng Wu <alexepico@gmail.com>
Tue, 14 Sep 2010 08:05:05 +0000 (16:05 +0800)
src/storage/phrase_index.cpp
src/storage/phrase_index.h

index ce23180..b4ffa7f 100644 (file)
@@ -351,3 +351,33 @@ int SubPhraseIndex::get_range(/* out */ PhraseIndexRange & range){
 
     return ERROR_OK;
 }
+
+bool FacadePhraseIndex::compat(){
+    for ( size_t index = 0; index < PHRASE_INDEX_LIBRARY_COUNT; ++index) {
+        SubPhraseIndex * sub_phrase = m_sub_phrase_indices[index];
+        if ( !sub_phrase )
+            continue;
+
+        SubPhraseIndex * new_sub_phrase =  new SubPhraseIndex;
+        PhraseIndexRange range;
+        int result = sub_phrase->get_range(range);
+        if ( result != ERROR_OK ) {
+            delete new_sub_phrase;
+            continue;
+        }
+
+        PhraseItem item;
+        for ( phrase_token_t token = range.m_range_begin;
+              token < range.m_range_end;
+              ++token ) {
+            result = sub_phrase->get_phrase_item(token, item);
+            if ( result != ERROR_OK )
+                continue;
+            new_sub_phrase->add_phrase_item(token, &item);
+        }
+
+        delete sub_phrase;
+        m_sub_phrase_indices[index] = new_sub_phrase;
+    }
+    return true;
+}
index 3f94bd3..c07b006 100755 (executable)
@@ -210,6 +210,9 @@ public:
     bool store(guint8 phrase_index, MemoryChunk * new_chunk);
     bool unload(guint8 phrase_index);
 
+    /* compat all SubPhraseIndex m_phrase_content memory usage.*/
+    bool compat();
+
     /* get each sub phrase token range with phrase_index added */
     int get_range(guint8 phrase_index, /* out */ PhraseIndexRange & range);