diff options
| author | Peng Wu <alexepico@gmail.com> | 2016-03-15 13:14:51 +0800 |
|---|---|---|
| committer | Peng Wu <alexepico@gmail.com> | 2016-03-15 13:14:51 +0800 |
| commit | 8f3603807183cbe4c05f5f3d926c809698aacb9d (patch) | |
| tree | 7cc5b82ea83e5b2a231cd92b9fb943bc19d6b725 /src/storage/chewing_large_table2.cpp | |
| parent | aedbe291325b62efee3307699107c9594e23d394 (diff) | |
| download | libpinyin-8f3603807183cbe4c05f5f3d926c809698aacb9d.tar.gz libpinyin-8f3603807183cbe4c05f5f3d926c809698aacb9d.tar.xz libpinyin-8f3603807183cbe4c05f5f3d926c809698aacb9d.zip | |
refactor code
Diffstat (limited to 'src/storage/chewing_large_table2.cpp')
| -rw-r--r-- | src/storage/chewing_large_table2.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/storage/chewing_large_table2.cpp b/src/storage/chewing_large_table2.cpp index 7f49772..9e9fd4a 100644 --- a/src/storage/chewing_large_table2.cpp +++ b/src/storage/chewing_large_table2.cpp @@ -150,3 +150,64 @@ bool ChewingLargeTable2::load_text(FILE * infile) { return true; } + +/* search method */ +int ChewingLargeTable2::search(int phrase_length, + /* in */ const ChewingKey keys[], + /* out */ PhraseIndexRanges ranges) const { + ChewingKey index[MAX_PHRASE_LENGTH]; + assert(NULL != m_db); + + if (contains_incomplete_pinyin(keys, phrase_length)) { + compute_incomplete_chewing_index(keys, index, phrase_length); + return search_internal(phrase_length, index, keys, ranges); + } else { + compute_chewing_index(keys, index, phrase_length); + return search_internal(phrase_length, index, keys, ranges); + } + + return SEARCH_NONE; +} + +/* add/remove index method */ +int ChewingLargeTable2::add_index(int phrase_length, + /* in */ const ChewingKey keys[], + /* in */ phrase_token_t token) { + ChewingKey index[MAX_PHRASE_LENGTH]; + assert(NULL != m_db); + int result = ERROR_OK; + + /* for in-complete chewing index */ + compute_incomplete_chewing_index(keys, index, phrase_length); + result = add_index_internal(phrase_length, index, keys, token); + assert(ERROR_OK == result || ERROR_INSERT_ITEM_EXISTS == result); + if (ERROR_OK != result) + return result; + + /* for chewing index */ + compute_chewing_index(keys, index, phrase_length); + result = add_index_internal(phrase_length, index, keys, token); + assert(ERROR_OK == result || ERROR_INSERT_ITEM_EXISTS == result); + return result; +} + +int ChewingLargeTable2::remove_index(int phrase_length, + /* in */ const ChewingKey keys[], + /* in */ phrase_token_t token) { + ChewingKey index[MAX_PHRASE_LENGTH]; + assert(NULL != m_db); + int result = ERROR_OK; + + /* for in-complete chewing index */ + compute_incomplete_chewing_index(keys, index, phrase_length); + result = remove_index_internal(phrase_length, index, keys, token); + assert(ERROR_OK == result || ERROR_REMOVE_ITEM_DONOT_EXISTS == result); + if (ERROR_OK != result) + return result; + + /* for chewing index */ + compute_chewing_index(keys, index, phrase_length); + result = remove_index_internal(phrase_length, index, keys, token); + assert(ERROR_OK == result || ERROR_REMOVE_ITEM_DONOT_EXISTS == result); + return result; +} |
