summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-08-27 13:34:40 +0800
committerPeng Wu <alexepico@gmail.com>2012-08-27 13:34:40 +0800
commit55424dc21ff006e91533d855dd4ad98c5bdc727a (patch)
tree56044695e53a19ff6d41338865be18f1859b1390
parent0b35cb6786587dc9d0a442f1cd0267d13d1f19c2 (diff)
downloadlibpinyin-55424dc21ff006e91533d855dd4ad98c5bdc727a.tar.gz
libpinyin-55424dc21ff006e91533d855dd4ad98c5bdc727a.tar.xz
libpinyin-55424dc21ff006e91533d855dd4ad98c5bdc727a.zip
begin to write search method
-rw-r--r--src/storage/phrase_large_table2.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp
index ad9c2bb..8974d26 100644
--- a/src/storage/phrase_large_table2.cpp
+++ b/src/storage/phrase_large_table2.cpp
@@ -102,3 +102,33 @@ static bool phrase_less_than(const PhraseIndexItem2<phrase_length> & lhs,
const PhraseIndexItem2<phrase_length> & rhs){
return 0 > phrase_compare(lhs, rhs);
}
+
+PhraseBitmapIndexLevel2::PhraseBitmapIndexLevel2(){
+ memset(m_phrase_length_indexes, 0, sizeof(m_phrase_length_indexes));
+}
+
+void PhraseBitmapIndexLevel2::reset(){
+ for ( size_t i = 0; i < PHRASE_NUMBER_OF_BITMAP_INDEX; i++){
+ PhraseLengthIndexLevel2 * length_array =
+ m_phrase_length_indexes[i];
+ if ( length_array )
+ delete length_array;
+ }
+}
+
+int PhraseBitmapIndexLevel2::search(int phrase_length,
+ /* in */ ucs4_t phrase[],
+ /* out */ PhraseTokens tokens) const {
+ assert(phrase_length > 0);
+
+ int result = SEARCH_NONE;
+ /* use the first 8-bit of the lower 16-bit for bitmap index,
+ * as most the higher 16-bit are zero.
+ */
+ guint8 first_key = (phrase[0] & 0xFF00) >> 8;
+
+ PhraseLengthIndexLevel2 * phrase_array = m_phrase_length_indexes[first_key];
+ if ( phrase_array )
+ return phrase_array->search(phrase_length, phrase, tokens);
+ return result;
+}