summaryrefslogtreecommitdiffstats
path: root/src/storage/phrase_index.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-10-26 14:15:23 +0800
committerPeng Wu <alexepico@gmail.com>2012-10-26 14:15:23 +0800
commitbdb3f3ae7ecfba97abcf0553b4325fe97725c3ed (patch)
treebda841e844f050dfd890010829bed1a09f3e4472 /src/storage/phrase_index.cpp
parent2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9 (diff)
downloadlibpinyin-bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed.tar.gz
libpinyin-bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed.tar.xz
libpinyin-bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed.zip
write FacadePhraseIndex::merge_with_mask
Diffstat (limited to 'src/storage/phrase_index.cpp')
-rw-r--r--src/storage/phrase_index.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index 6864387..be78dfa 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -251,6 +251,40 @@ bool FacadePhraseIndex::merge(guint8 phrase_index, MemoryChunk * log){
return retval;
}
+bool FacadePhraseIndex::merge_with_mask(guint8 phrase_index,
+ MemoryChunk * log,
+ phrase_token_t mask,
+ phrase_token_t value){
+ SubPhraseIndex * & sub_phrases = m_sub_phrase_indices[phrase_index];
+ if ( !sub_phrases )
+ return false;
+
+ /* check mask and value. */
+ phrase_token_t index_mask = PHRASE_INDEX_LIBRARY_INDEX(mask);
+ phrase_token_t index_value = PHRASE_INDEX_LIBRARY_INDEX(value);
+ if (!((index_mask & phrase_index) == index_value))
+ return false;
+
+ /* unload old sub phrase index */
+ m_total_freq -= sub_phrases->get_phrase_index_total_freq();
+
+ /* calculate the sub phrase index mask and value. */
+ mask &= PHRASE_MASK; value &= PHRASE_MASK;
+
+ /* prepare the new logger. */
+ PhraseIndexLogger oldlogger;
+ oldlogger.load(log);
+ PhraseIndexLogger * newlogger = mask_out_phrase_index_logger
+ (&oldlogger, mask, value);
+
+ bool retval = sub_phrases->merge(newlogger);
+ m_total_freq += sub_phrases->get_phrase_index_total_freq();
+ delete newlogger;
+
+ return retval;
+}
+
+
bool SubPhraseIndex::load(MemoryChunk * chunk,
table_offset_t offset, table_offset_t end){
//save the memory chunk