bool SubPhraseIndex::merge(PhraseIndexLogger * logger){
LOG_TYPE log_type; phrase_token_t token;
MemoryChunk oldchunk, newchunk;
- PhraseItem olditem, newitem, * tmpitem;
+ PhraseItem olditem, newitem, item, * tmpitem;
while(logger->has_next_record()){
logger->next_record(log_type, token, &oldchunk, &newchunk);
assert( 0 == newchunk.size() );
tmpitem = NULL;
remove_phrase_item(token, tmpitem);
+
olditem.m_chunk.set_chunk(oldchunk.begin(), oldchunk.size(),
NULL);
if (olditem != *tmpitem)
return false;
+ delete tmpitem;
+
break;
}
case LOG_MODIFY_RECORD:{
- TODO:
+ get_phrase_item(token, item);
+ olditem.m_chunk.set_chunk(oldchunk.begin(), oldchunk.size(),
+ NULL);
+ newitem.m_chunk.set_chunk(newchunk.begin(), newchunk.size(),
+ NULL);
+ if (item != olditem)
+ return false;
+
+ if (newchunk.size() > item.m_chunk.size() ){ /* increase size. */
+ tmpitem = NULL;
+ remove_phrase_item(token, tmpitem);
+ assert(olditem == *tmpitem);
+ add_phrase_item(token, &newitem);
+ delete tmpitem;
+ } else { /* in place editing. */
+ /* newchunk.size() <= item.m_chunk.size() */
+ /* Hack here: we assume the behaviour of get_phrase_item
+ * point to the actual data positon, so changes to item
+ * will be saved in SubPhraseIndex immediately.
+ */
+ memmove(item.m_chunk.begin(), newchunk.begin(),
+ newchunk.size());
+ }
break;
}
default:
/* Zero-gram */
guint32 get_phrase_index_total_freq();
int add_unigram_frequency(phrase_token_t token, guint32 delta);
- /* get_phrase_item function can't modify the phrase item,
- * but can increment the freq of the special pronunciation.
+
+ /* get_phrase_item function can't modify the phrase item size,
+ * but can increment the freq of the special pronunciation,
+ * or change the content without size increasing.
*/
int get_phrase_item(phrase_token_t token, PhraseItem & item);
int add_phrase_item(phrase_token_t token, PhraseItem * item);