summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-03-15 13:47:10 +0800
committerPeng Wu <alexepico@gmail.com>2016-03-15 13:47:10 +0800
commit6f7db0c76f4557245c51b4fe4ab1b9973cad8c74 (patch)
tree8faa861df98bfcdbb93369a987eaa195dae4ab8e /src
parent63ad8a96490927f6261089e7c59d23d00cb2f069 (diff)
downloadlibpinyin-6f7db0c76f4557245c51b4fe4ab1b9973cad8c74.tar.gz
libpinyin-6f7db0c76f4557245c51b4fe4ab1b9973cad8c74.tar.xz
libpinyin-6f7db0c76f4557245c51b4fe4ab1b9973cad8c74.zip
write search method
Diffstat (limited to 'src')
-rw-r--r--src/storage/chewing_large_table2_kyotodb.cpp68
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;
+}
+
};