diff options
author | Peng Wu <alexepico@gmail.com> | 2010-08-27 14:24:02 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2010-08-27 14:24:02 +0800 |
commit | b0ea21fda50b43d964f8ddc84f62ff3bb61043c8 (patch) | |
tree | ef3b2cffe805f51f78b4f9b4f61fbf12d519d01a /src/storage | |
parent | 38068dc1f723f3960c144d82ec74eab7ecae9a31 (diff) | |
download | libpinyin-b0ea21fda50b43d964f8ddc84f62ff3bb61043c8.tar.gz libpinyin-b0ea21fda50b43d964f8ddc84f62ff3bb61043c8.tar.xz libpinyin-b0ea21fda50b43d964f8ddc84f62ff3bb61043c8.zip |
begin to add add_index/remove_index.
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/phrase_large_table.cpp | 91 | ||||
-rw-r--r-- | src/storage/pinyin_large_table.cpp | 4 |
2 files changed, 93 insertions, 2 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 +} diff --git a/src/storage/pinyin_large_table.cpp b/src/storage/pinyin_large_table.cpp index 9f0f8ee..7d0ac4a 100644 --- a/src/storage/pinyin_large_table.cpp +++ b/src/storage/pinyin_large_table.cpp @@ -390,13 +390,13 @@ int PinyinLengthIndexLevel::add_index( int phrase_length, /* in */ PinyinKey key int PinyinLengthIndexLevel::remove_index( int phrase_length, /* in */ PinyinKey keys[], /* in */ phrase_token_t token){ assert(phrase_length + 1 < MAX_PHRASE_LENGTH); if ( m_pinyin_array_indexes -> len <= phrase_length ) - return false; + return REMOVE_ITEM_DONOT_EXISTS; #define CASE(len) case len: \ { \ PinyinArrayIndexLevel<len> * &array = g_array_index \ (m_pinyin_array_indexes, PinyinArrayIndexLevel<len> *, len); \ if ( !array ) \ - return false; \ + return REMOVE_ITEM_DONOT_EXISTS; \ return array->remove_index(keys, token); \ } switch(phrase_length){ |