summaryrefslogtreecommitdiffstats
path: root/src/storage/chewing_large_table2.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-03-15 13:14:51 +0800
committerPeng Wu <alexepico@gmail.com>2016-03-15 13:14:51 +0800
commit8f3603807183cbe4c05f5f3d926c809698aacb9d (patch)
tree7cc5b82ea83e5b2a231cd92b9fb943bc19d6b725 /src/storage/chewing_large_table2.cpp
parentaedbe291325b62efee3307699107c9594e23d394 (diff)
downloadlibpinyin-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.cpp61
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;
+}