diff options
author | Peng Wu <alexepico@gmail.com> | 2016-02-18 11:33:18 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-02-18 11:33:18 +0800 |
commit | e4040fc2362e077cbe92eb2deaa18f1c2c11dc40 (patch) | |
tree | a3d8c3a8e6b1a06c5184d8991461e28e433a4be6 /src/storage/phrase_large_table3_kyotodb.cpp | |
parent | 0d5cec839163b988213108ffcff3141aee7c898b (diff) | |
download | libpinyin-e4040fc2362e077cbe92eb2deaa18f1c2c11dc40.tar.gz libpinyin-e4040fc2362e077cbe92eb2deaa18f1c2c11dc40.tar.xz libpinyin-e4040fc2362e077cbe92eb2deaa18f1c2c11dc40.zip |
write search method
Diffstat (limited to 'src/storage/phrase_large_table3_kyotodb.cpp')
-rw-r--r-- | src/storage/phrase_large_table3_kyotodb.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/storage/phrase_large_table3_kyotodb.cpp b/src/storage/phrase_large_table3_kyotodb.cpp index ce99c99..fd7d476 100644 --- a/src/storage/phrase_large_table3_kyotodb.cpp +++ b/src/storage/phrase_large_table3_kyotodb.cpp @@ -42,8 +42,6 @@ void PhraseLargeTable3::reset() { m_db = NULL; } - m_chunk.set_size(0); - if (m_entry) { delete m_entry; m_entry = NULL; @@ -144,5 +142,36 @@ bool PhraseLargeTable3::store_db(const char * new_filename){ return true; } +/* search method */ +int PhraseLargeTable3::search(int phrase_length, + /* in */ const ucs4_t phrase[], + /* out */ PhraseTokens tokens) const { + int result = SEARCH_NONE; + + if (NULL == m_db) + return result; + assert(NULL != m_entry); + + const char * kbuf = (char *) phrase; + const int32_t vsiz = m_db->check(kbuf, phrase_length * sizeof(ucs4_t)); + /* -1 on failure. */ + if (-1 == vsiz) + return result; + + /* continue searching. */ + result |= SEARCH_CONTINUED; + if (0 == vsiz) + return result; + + m_entry->m_chunk.set_size(vsiz); + char * vbuf = (char *) m_entry->m_chunk.begin(); + assert (vsiz == m_db->get(kbuf, phrase_length * sizeof(ucs4_t), + vbuf, vsiz)); + + result = m_entry->search(tokens) | result; + + return result; +} + }; |