diff options
author | Peng Wu <alexepico@gmail.com> | 2012-05-16 14:50:41 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-05-16 14:50:41 +0800 |
commit | 91109001e08ce8cd2748692eb8a031ef7e763896 (patch) | |
tree | c902a015ac79a61fc75c04d2011837b09c64f3c3 /src/lookup | |
parent | ef71c282849298f8c8065bd8d6f8d5a4c385e4db (diff) | |
download | libpinyin-91109001e08ce8cd2748692eb8a031ef7e763896.tar.gz libpinyin-91109001e08ce8cd2748692eb8a031ef7e763896.tar.xz libpinyin-91109001e08ce8cd2748692eb8a031ef7e763896.zip |
update pinyin_lookup.*
Diffstat (limited to 'src/lookup')
-rw-r--r-- | src/lookup/pinyin_lookup.cpp | 31 | ||||
-rw-r--r-- | src/lookup/pinyin_lookup.h | 4 |
2 files changed, 5 insertions, 30 deletions
diff --git a/src/lookup/pinyin_lookup.cpp b/src/lookup/pinyin_lookup.cpp index 432acc1..bdcfd0b 100644 --- a/src/lookup/pinyin_lookup.cpp +++ b/src/lookup/pinyin_lookup.cpp @@ -73,12 +73,13 @@ PinyinLookup::~PinyinLookup(){ if ( m_winner_tree ) delete m_winner_tree; m_winner_tree = NULL; + //free resources for ( size_t i = 0; i < m_table_cache->len; ++i){ PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, i); - destroy_pinyin_lookup(*ranges); + m_phrase_index->destroy_ranges(*ranges); } - //g_array_set_size(m_table_cache, 1); + g_array_free(m_table_cache, TRUE); clear_steps(m_steps_index, m_steps_content); @@ -86,33 +87,11 @@ PinyinLookup::~PinyinLookup(){ g_ptr_array_free(m_steps_content, TRUE); } -bool PinyinLookup::prepare_pinyin_lookup(PhraseIndexRanges ranges){ - //memset(ranges, 0, sizeof(ranges)); - for ( size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i ){ - GArray * & array = ranges[i]; - assert(NULL == array); - if (m_phrase_index->m_sub_phrase_indices[i]){ - array = g_array_new(FALSE, FALSE, sizeof (PhraseIndexRange)); - } - } - return true; -} - -bool PinyinLookup::destroy_pinyin_lookup(PhraseIndexRanges ranges){ - for ( size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){ - GArray * & array = ranges[i]; - if ( array ) - g_array_free(array, TRUE); - array = NULL; - } - return true; -} - size_t PinyinLookup::prepare_table_cache(int nstep, int total_pinyin){ /* free resources */ for ( size_t i = 0; i < m_table_cache->len; ++i){ PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, i); - destroy_pinyin_lookup(*ranges); + m_phrase_index->destroy_ranges(*ranges); } ChewingKey * pinyin_keys = (ChewingKey *)m_keys->data; @@ -123,7 +102,7 @@ size_t PinyinLookup::prepare_table_cache(int nstep, int total_pinyin){ for ( len = 1; len <= total_len; ++len){ PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, len); - prepare_pinyin_lookup(*ranges); + m_phrase_index->prepare_ranges(*ranges); int result = m_pinyin_table->search(len, pinyin_keys, *ranges); if (!( result & SEARCH_CONTINUED)){ ++len; diff --git a/src/lookup/pinyin_lookup.h b/src/lookup/pinyin_lookup.h index 5715526..b23c39a 100644 --- a/src/lookup/pinyin_lookup.h +++ b/src/lookup/pinyin_lookup.h @@ -126,10 +126,6 @@ protected: WinnerTree * m_winner_tree; size_t prepare_table_cache(int nstep, int total_pinyin); - /* init pinyin table lookup array */ - bool prepare_pinyin_lookup(PhraseIndexRanges ranges); - /* destroy pinyin table lookup array */ - bool destroy_pinyin_lookup(PhraseIndexRanges ranges); bool search_unigram(IBranchIterator * iter, int nstep, int npinyin); bool search_bigram(IBranchIterator * iter, int nstep, int npinyin); |