summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2022-08-30 11:51:18 +0800
committerPeng Wu <alexepico@gmail.com>2022-08-30 11:51:18 +0800
commit20ad271a95ff149422a55b8dbe985c114a5a27e4 (patch)
tree20effac3046957c41ebdec4f3c83865c65062e7c
parent008794423b00488ee45fb204bf5c6fc5205475cb (diff)
downloadlibpinyin-20ad271a95ff149422a55b8dbe985c114a5a27e4.tar.gz
Fix Kyoto Cabinet usage
-rw-r--r--src/pinyin.cpp2
-rw-r--r--src/storage/phrase_large_table3.h8
-rw-r--r--src/storage/phrase_large_table3_kyotodb.cpp3
3 files changed, 9 insertions, 4 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 76ab61a..6bef386 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -2089,7 +2089,7 @@ bool pinyin_guess_predicted_candidates(pinyin_instance_t * instance,
phrase_index->prepare_tokens(phrase_tokens);
int result = context->m_phrase_table->search_suggestion
(instance->m_prefix_len, instance->m_prefix_ucs4, phrase_tokens);
- int num = reduce_tokens(phrase_tokens, tokenarray);
+ int num = reduce_tokens(phrase_tokens, tokenarray, false);
phrase_index->destroy_tokens(phrase_tokens);
for (size_t i = 0; i < tokenarray->len; ++i) {
diff --git a/src/storage/phrase_large_table3.h b/src/storage/phrase_large_table3.h
index 40654bb..b4da01d 100644
--- a/src/storage/phrase_large_table3.h
+++ b/src/storage/phrase_large_table3.h
@@ -69,7 +69,8 @@ public:
static inline int reduce_tokens(const PhraseTokens tokens,
- TokenVector tokenarray) {
+ TokenVector tokenarray,
+ bool validate = true) {
int num = 0;
g_array_set_size(tokenarray, 0);
@@ -83,8 +84,9 @@ static inline int reduce_tokens(const PhraseTokens tokens,
g_array_append_vals(tokenarray, array->data, array->len);
}
- /* the following line will be removed in future after code are verified. */
- assert(0 <= num && num <= 4);
+ /* the following lines will be removed in future after code are verified. */
+ if (validate)
+ assert(0 <= num && num <= 4);
return num;
}
diff --git a/src/storage/phrase_large_table3_kyotodb.cpp b/src/storage/phrase_large_table3_kyotodb.cpp
index fcd8a03..2ff9990 100644
--- a/src/storage/phrase_large_table3_kyotodb.cpp
+++ b/src/storage/phrase_large_table3_kyotodb.cpp
@@ -238,6 +238,9 @@ int PhraseLargeTable3::search_suggestion(int phrase_length,
delete cursor;
return result;
}
+
+ bksiz = 0;
+ bkbuf = cursor->get_key(&bksiz);
}
delete cursor;