summaryrefslogtreecommitdiffstats
path: root/src/storage/phrase_large_table.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-08-27 14:24:02 +0800
committerPeng Wu <alexepico@gmail.com>2010-08-27 14:24:02 +0800
commitb0ea21fda50b43d964f8ddc84f62ff3bb61043c8 (patch)
treeef3b2cffe805f51f78b4f9b4f61fbf12d519d01a /src/storage/phrase_large_table.cpp
parent38068dc1f723f3960c144d82ec74eab7ecae9a31 (diff)
downloadlibpinyin-b0ea21fda50b43d964f8ddc84f62ff3bb61043c8.tar.gz
libpinyin-b0ea21fda50b43d964f8ddc84f62ff3bb61043c8.tar.xz
libpinyin-b0ea21fda50b43d964f8ddc84f62ff3bb61043c8.zip
begin to add add_index/remove_index.
Diffstat (limited to 'src/storage/phrase_large_table.cpp')
-rw-r--r--src/storage/phrase_large_table.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/storage/phrase_large_table.cpp b/src/storage/phrase_large_table.cpp
index d7941cd..0da55e8 100644
--- a/src/storage/phrase_large_table.cpp
+++ b/src/storage/phrase_large_table.cpp
@@ -174,3 +174,94 @@ int PhraseArrayIndexLevel<phrase_length>::search(/* in */ utf16_t phrase[], /* o
token = range.first->m_token;
return SEARCH_OK;
}
+
+int PhraseBitmapIndexLevel::add_index( int phrase_length, /* in */ utf16_t phrase[], /* in */ phrase_token_t token){
+ utf16_t first_key = phrase[0];
+ PhraseLengthIndexLevel * & length_array = m_phrase_length_indexes[first_key];
+ if ( !length_array ){
+ length_array = new PhraseLengthIndexLevel();
+ }
+ return length_array->add_index(phrase_length - 1, phrase + 1, token);
+}
+
+int PhraseBitmapIndexLevel::remove_index( int phrase_length, /* in */ utf16_t phrase[], /* out */ phrase_token_t & token){
+ utf16_t first_key = phrase[0];
+ PhraseLengthIndexLevel * &length_array = m_phrase_length_indexes[first_key];
+ if ( length_array )
+ return length_array->remove_index(phrase_length - 1, phrase + 1, token);
+ return REMOVE_ITEM_DONOT_EXISTS;
+}
+
+int PhraseLengthIndexLevel::add_index( int phrase_length, /* in */ utf16_t phrase[], /* in */ phrase_token_t token){
+ assert(phrase_length + 1 < MAX_PHRASE_LENGTH);
+ if ( m_phrase_array_indexes -> len <= phrase_length )
+ g_array_set_size(m_phrase_array_indexes, phrase_length + 1);
+
+#define CASE(len) case len: \
+ { \
+ PhraseArrayIndexLevel<len> * &array = g_array_index \
+ (m_phrase_array_indexes, PhraseArrayIndexLevel<len> *, len); \
+ if ( !array ) \
+ array = new PhraseArrayIndexLevel<len>; \
+ return array->add_index(phrase, token); \
+ }
+
+ switch(phrase_length){
+ CASE(0);
+ 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);
+ default:
+ assert(false);
+ }
+
+#undef CASE
+}
+
+int PhraseLengthIndexLevel::remove_index( int phrase_length, /* in */ utf16_t phrase[], /* out */ phrase_token_t & token){
+ assert(phrase_length + 1 < MAX_PHRASE_LENGTH);
+ if ( m_phrase_array_indexes -> len <= phrase_length )
+ return REMOVE_ITEM_DONOT_EXISTS;
+#define CASE(len) case len: \
+ { \
+ PhraseArrayIndexLevel<len> * &array = g_array_index \
+ (m_phrase_array_indexes, PhraseArrayIndexLevel<len> *, len); \
+ if ( !array ) \
+ return REMOVE_ITEM_DONOT_EXISTS; \
+ return array->remove_index(phrase, token); \
+ }
+
+ switch(phrase_length){
+ CASE(0);
+ 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);
+ default:
+ assert(false);
+ }
+#undef CASE
+}