summaryrefslogtreecommitdiffstats
path: root/src/storage/phrase_index.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-09-14 16:05:05 +0800
committerPeng Wu <alexepico@gmail.com>2010-09-14 16:05:05 +0800
commit9a5f7fb359c1a6ea6a6fde624473bfd4777b68a4 (patch)
tree220d23498b88345ea58c4c6859c9d8356a4ddccd /src/storage/phrase_index.cpp
parent2003b8b7c033a64395d69dd9bb445d8a13077430 (diff)
downloadlibpinyin-9a5f7fb359c1a6ea6a6fde624473bfd4777b68a4.tar.gz
libpinyin-9a5f7fb359c1a6ea6a6fde624473bfd4777b68a4.tar.xz
libpinyin-9a5f7fb359c1a6ea6a6fde624473bfd4777b68a4.zip
add compat method for phrase index
Diffstat (limited to 'src/storage/phrase_index.cpp')
-rw-r--r--src/storage/phrase_index.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index ce23180..b4ffa7f 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -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;
+}