diff options
author | Peng Wu <alexepico@gmail.com> | 2017-01-17 15:21:10 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2017-01-17 15:21:10 +0800 |
commit | 53948ad9daa5efd0da6e2e01f8e0e4545283fc1e (patch) | |
tree | d59b70c310371c88eebd1cb06ee9d24f10d4a0d5 /src/lookup | |
parent | 2a2cd0f9de33b1f92a30cee2b5966f3a7a3eccdb (diff) | |
download | libpinyin-53948ad9daa5efd0da6e2e01f8e0e4545283fc1e.tar.gz libpinyin-53948ad9daa5efd0da6e2e01f8e0e4545283fc1e.tar.xz libpinyin-53948ad9daa5efd0da6e2e01f8e0e4545283fc1e.zip |
write clear and prepare methods
Diffstat (limited to 'src/lookup')
-rw-r--r-- | src/lookup/phonetic_lookup.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h index 6ca7d4f..65602c7 100644 --- a/src/lookup/phonetic_lookup.h +++ b/src/lookup/phonetic_lookup.h @@ -117,8 +117,38 @@ private: GPtrArray * m_steps_content; public: - bool clear(); - bool prepare(gint32 nstep); + bool clear() { + /* clear 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 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; + } + + return true; + } + + bool prepare(gint32 nstep) { + /* add null start step */ + g_ptr_array_set_size(m_steps_index, nstep); + g_ptr_array_set_size(m_steps_content, nstep); + + for (int i = 0; i < nstep; ++i) { + /* initialize m_steps_index */ + g_ptr_array_index(m_steps_index, i) = g_hash_table_new(g_direct_hash, g_direct_equal); + /* initialize m_steps_content */ + g_ptr_array_index(m_steps_content, i) = g_array_new(FALSE, FALSE, sizeof(trellis_node<nbest>)); + } + + return true; + } /* Array of phrase_token_t */ bool fill_prefixes(/* in */ TokenVector prefixes); |