summaryrefslogtreecommitdiffstats
path: root/src/lookup
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-02-29 15:50:25 +0800
committerPeng Wu <alexepico@gmail.com>2012-02-29 15:50:25 +0800
commitd8db8c691894e653477c28dc13cff5e8db60502c (patch)
tree36c22ba06b82d29491f7c127253df0e15eb186ac /src/lookup
parent20acf51bad185665f9ef1ab4c46399befe93b28a (diff)
downloadlibpinyin-d8db8c691894e653477c28dc13cff5e8db60502c.tar.gz
libpinyin-d8db8c691894e653477c28dc13cff5e8db60502c.tar.xz
libpinyin-d8db8c691894e653477c28dc13cff5e8db60502c.zip
clean up pinyin_lookup.cpp
Diffstat (limited to 'src/lookup')
-rw-r--r--src/lookup/pinyin_lookup.cpp45
1 files changed, 18 insertions, 27 deletions
diff --git a/src/lookup/pinyin_lookup.cpp b/src/lookup/pinyin_lookup.cpp
index 2c6974f..0281923 100644
--- a/src/lookup/pinyin_lookup.cpp
+++ b/src/lookup/pinyin_lookup.cpp
@@ -35,6 +35,22 @@ using namespace pinyin;
const gfloat PinyinLookup::bigram_lambda = LAMBDA_PARAMETER;
const gfloat PinyinLookup::unigram_lambda = 1 - LAMBDA_PARAMETER;
+static void clear_steps(GPtrArray * steps_index, GPtrArray * steps_content){
+ /* clear steps_index */
+ for ( size_t i = 0; i < steps_index->len; ++i){
+ GHashTable * table = (GHashTable *) g_ptr_array_index(steps_index, i);
+ g_hash_table_destroy(table);
+ g_ptr_array_index(steps_index, i) = NULL;
+ }
+
+ /* clear steps_content */
+ for ( size_t i = 0; i < steps_content->len; ++i){
+ GArray * array = (GArray *) g_ptr_array_index(steps_content, i);
+ g_array_free(array, TRUE);
+ g_ptr_array_index(steps_content, i) = NULL;
+ }
+}
+
PinyinLookup::PinyinLookup(pinyin_option_t options,
FacadeChewingTable * pinyin_table,
FacadePhraseIndex * phrase_index,
@@ -65,22 +81,9 @@ PinyinLookup::~PinyinLookup(){
//g_array_set_size(m_table_cache, 1);
g_array_free(m_table_cache, TRUE);
- //free m_steps_index
- for ( size_t i = 0; i < m_steps_index->len; ++i){
- GHashTable * table = (GHashTable *) g_ptr_array_index(m_steps_index, i);
- g_hash_table_destroy(table);
- g_ptr_array_index(m_steps_index, i) = NULL;
- }
+ clear_steps(m_steps_index, m_steps_content);
g_ptr_array_free(m_steps_index, TRUE);
-
- //free m_steps_content
- for ( size_t i = 0; i < m_steps_content->len; ++i){
- GArray * array = (GArray *) g_ptr_array_index(m_steps_content, i);
- g_array_free(array, TRUE);
- g_ptr_array_index(m_steps_content, i) = NULL;
- }
g_ptr_array_free(m_steps_content, TRUE);
-
}
bool PinyinLookup::prepare_pinyin_lookup(PhraseIndexRanges ranges){
@@ -147,19 +150,7 @@ bool PinyinLookup::get_best_match(ChewingKeyVector keys, CandidateConstraints co
m_keys = keys;
int nstep = keys->len + 1;
- //free m_steps_index
- for ( size_t i = 0; i < m_steps_index->len; ++i){
- GHashTable * table = (GHashTable *) g_ptr_array_index(m_steps_index, i);
- g_hash_table_destroy(table);
- g_ptr_array_index(m_steps_index, i) = NULL;
- }
-
- //free m_steps_content
- for ( size_t i = 0; i < m_steps_content->len; ++i){
- GArray * array = (GArray *) g_ptr_array_index(m_steps_content, i);
- g_array_free(array, TRUE);
- g_ptr_array_index(m_steps_content, i) = NULL;
- }
+ clear_steps(m_steps_index, m_steps_content);
//add null start step
g_ptr_array_set_size(m_steps_index, nstep);