summaryrefslogtreecommitdiffstats
path: root/src/storage/phrase_index.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-10-26 12:06:43 +0800
committerPeng Wu <alexepico@gmail.com>2012-10-26 12:09:12 +0800
commit2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9 (patch)
treecdf7791edad77d1a675dc8e4d33f0e856bb4ef51 /src/storage/phrase_index.cpp
parentfb62ce874969fe4111f3592f55e2c0dcbf2e6d9c (diff)
downloadlibpinyin-2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9.tar.gz
libpinyin-2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9.tar.xz
libpinyin-2a765c8a8171b8283b2cee5c9fd80bb0eeca50b9.zip
re-factor phrase index
Diffstat (limited to 'src/storage/phrase_index.cpp')
-rw-r--r--src/storage/phrase_index.cpp16
1 files 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;