diff options
author | Peng Wu <alexepico@gmail.com> | 2012-10-26 14:15:23 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-10-26 14:15:23 +0800 |
commit | bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed (patch) | |
tree | bda841e844f050dfd890010829bed1a09f3e4472 /src | |
parent | 2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9 (diff) | |
download | libpinyin-bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed.tar.gz libpinyin-bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed.tar.xz libpinyin-bdb3f3ae7ecfba97abcf0553b4325fe97725c3ed.zip |
write FacadePhraseIndex::merge_with_mask
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/phrase_index.cpp | 34 | ||||
-rw-r--r-- | src/storage/phrase_index.h | 19 |
2 files changed, 51 insertions, 2 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 diff --git a/src/storage/phrase_index.h b/src/storage/phrase_index.h index e9f4764..7eb79fc 100644 --- a/src/storage/phrase_index.h +++ b/src/storage/phrase_index.h @@ -533,6 +533,22 @@ public: bool merge(guint8 phrase_index, MemoryChunk * log); /** + * FacadePhraseIndex::merge_with_mask: + * @phrase_index: the index of sub phrase index to be merged. + * @log: the logger of difference in user home directory. + * @mask: the mask. + * @value: the value. + * @returns: whether the merge operation is successful. + * + * Merge the user logger of difference with mask operation. + * + * Note: the ownership of log is transfered here. + * + */ + bool merge_with_mask(guint8 phrase_index, MemoryChunk * log, + phrase_token_t mask, phrase_token_t value); + + /** * FacadePhraseIndex::compact: * @returns: whether the compact operation is successful. * @@ -806,8 +822,7 @@ typedef struct { extern const pinyin_table_info_t pinyin_phrase_files[PHRASE_INDEX_LIBRARY_COUNT]; PhraseIndexLogger * mask_out_phrase_index_logger -(const PhraseIndexLogger * oldlogger, phrase_token_t mask, - phrase_token_t value); +(PhraseIndexLogger * oldlogger, phrase_token_t mask, phrase_token_t value); }; |