diff options
Diffstat (limited to 'src/storage/chewing_large_table2_kyotodb.cpp')
-rw-r--r-- | src/storage/chewing_large_table2_kyotodb.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/storage/chewing_large_table2_kyotodb.cpp b/src/storage/chewing_large_table2_kyotodb.cpp index 596edd6..6cc401b 100644 --- a/src/storage/chewing_large_table2_kyotodb.cpp +++ b/src/storage/chewing_large_table2_kyotodb.cpp @@ -108,4 +108,72 @@ bool ChewingLargeTable2::store_db(const char * new_filename) { return true; } +template<int phrase_length> +int ChewingLargeTable2::search_internal(/* in */ const ChewingKey index[], + /* in */ const ChewingKey keys[], + /* out */ PhraseIndexRanges ranges) const { + int result = SEARCH_NONE; + + ChewingTableEntry<phrase_length> * entry = + (ChewingTableEntry<phrase_length> *) + g_ptr_array_index(m_entries, phrase_length); + assert(NULL != entry); + + const char * kbuf = (char *) index; + const int32_t vsiz = m_db->check(kbuf, phrase_length * sizeof(ChewingKey)); + /* -1 on failure. */ + if (-1 == vsiz) + return result; + + /* continue searching. */ + result |= SEARCH_CONTINUED; + if (0 == vsiz) + return result; + + entry->m_chunk.set_size(vsiz); + /* m_chunk may re-allocate here. */ + char * vbuf = (char *) entry->m_chunk.begin(); + assert(vsiz == m_db->get(kbuf, phrase_length * sizeof(ChewingKey), + vbuf, vsiz)); + + result = entry->search(keys, ranges) | result; + + return result; +} + +int ChewingLargeTable2::search_internal(int phrase_length, + /* in */ const ChewingKey index[], + /* in */ const ChewingKey keys[], + /* out */ PhraseIndexRanges ranges) const { +#define CASE(len) case len: \ + { \ + return search_internal<len>(index, keys, ranges); \ + } + + switch(phrase_length) { + CASE(1); + CASE(2); + CASE(3); + CASE(4); + CASE(5); + CASE(6); + CASE(7); + CASE(8); + CASE(9); + CASE(10); + CASE(11); + CASE(12); + CASE(13); + CASE(14); + CASE(15); + CASE(16); + default: + assert(false); + } + +#undef CASE + + return SEARCH_NONE; +} + }; |