From 2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 26 Oct 2012 12:06:43 +0800 Subject: re-factor phrase index --- src/storage/phrase_index.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp index ccf9354..6864387 100644 --- a/src/storage/phrase_index.cpp +++ b/src/storage/phrase_index.cpp @@ -530,8 +530,15 @@ int SubPhraseIndex::get_range(/* out */ PhraseIndexRange & range){ const table_offset_t * begin = (const table_offset_t *)m_phrase_index.begin(); const table_offset_t * end = (const table_offset_t *)m_phrase_index.end(); + /* remove trailing zeros. */ + const table_offset_t * poffset = 0; + for (poffset = end - 1; poffset >= begin + 1; --poffset) { + if (0 != *poffset) + break; + } + range.m_range_begin = 1; /* token starts with 1 in gen_pinyin_table. */ - range.m_range_end = end - begin; + range.m_range_end = poffset + 1 - begin; /* removed zeros. */ return ERROR_OK; } @@ -542,13 +549,12 @@ bool FacadePhraseIndex::compact(){ 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; + if ( result != ERROR_OK ) continue; - } + + SubPhraseIndex * new_sub_phrase = new SubPhraseIndex; PhraseItem item; for ( phrase_token_t token = range.m_range_begin; -- cgit