summaryrefslogtreecommitdiffstats
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
parentaedbe291325b62efee3307699107c9594e23d394 (diff)
downloadlibpinyin-8f3603807183cbe4c05f5f3d926c809698aacb9d.tar.gz
libpinyin-8f3603807183cbe4c05f5f3d926c809698aacb9d.tar.xz
libpinyin-8f3603807183cbe4c05f5f3d926c809698aacb9d.zip
refactor code
-rw-r--r--src/storage/chewing_large_table2.cpp61
-rw-r--r--src/storage/chewing_large_table2_bdb.cpp59
2 files changed, 61 insertions, 59 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;
+}
diff --git a/src/storage/chewing_large_table2_bdb.cpp b/src/storage/chewing_large_table2_bdb.cpp
index 2ecfced..1c7c97b 100644
--- a/src/storage/chewing_large_table2_bdb.cpp
+++ b/src/storage/chewing_large_table2_bdb.cpp
@@ -204,23 +204,6 @@ int ChewingLargeTable2::search_internal(int phrase_length,
return SEARCH_NONE;
}
-/* 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;
-}
template<int phrase_length>
int ChewingLargeTable2::add_index_internal(/* in */ const ChewingKey index[],
@@ -328,27 +311,6 @@ int ChewingLargeTable2::add_index_internal(int phrase_length,
return ERROR_FILE_CORRUPTION;
}
-/* 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;
-}
template<int phrase_length>
int ChewingLargeTable2::remove_index_internal(/* in */ const ChewingKey index[],
@@ -423,27 +385,6 @@ int ChewingLargeTable2::remove_index_internal(int phrase_length,
return ERROR_FILE_CORRUPTION;
}
-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;
-}
-
/* mask out method */
/* assume it is in-memory dbm. */
bool ChewingLargeTable2::mask_out(phrase_token_t mask,