From 20ad271a95ff149422a55b8dbe985c114a5a27e4 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 30 Aug 2022 11:51:18 +0800 Subject: Fix Kyoto Cabinet usage --- src/pinyin.cpp | 2 +- src/storage/phrase_large_table3.h | 8 +++++--- src/storage/phrase_large_table3_kyotodb.cpp | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') 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; -- cgit v1.2.1