diff options
author | Peng Wu <alexepico@gmail.com> | 2012-08-27 16:08:58 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-08-27 16:08:58 +0800 |
commit | 457445fdc6cd0e5446665ec05a8fe25d6d9d49eb (patch) | |
tree | 8dc5f468b9c47a291f72e682ef1fd97d2a774e3a /src/storage/phrase_large_table2.cpp | |
parent | f92f44995afc6e3ec2c1ea84a5083754e34a0d79 (diff) | |
download | libpinyin-457445fdc6cd0e5446665ec05a8fe25d6d9d49eb.tar.gz libpinyin-457445fdc6cd0e5446665ec05a8fe25d6d9d49eb.tar.xz libpinyin-457445fdc6cd0e5446665ec05a8fe25d6d9d49eb.zip |
write search method
Diffstat (limited to 'src/storage/phrase_large_table2.cpp')
-rw-r--r-- | src/storage/phrase_large_table2.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp index 79351fe..4a0d969 100644 --- a/src/storage/phrase_large_table2.cpp +++ b/src/storage/phrase_large_table2.cpp @@ -216,3 +216,44 @@ int PhraseLengthIndexLevel2::search(int phrase_length, } #undef CASE } + +template<size_t phrase_length> +int PhraseArrayIndexLevel2<phrase_length>::search +(/* in */ ucs4_t phrase[], /* out */ PhraseTokens tokens) const { + int result = SEARCH_NONE; + + IndexItem * chunk_begin = NULL, * chunk_end = NULL; + chunk_begin = (IndexItem *) m_chunk.begin(); + chunk_end = (IndexItem *) m_chunk.end(); + + /* do the search */ + IndexItem item(phrase, -1); + std_lite::pair<IndexItem *, IndexItem *> range; + range = std_lite::equal_range + (chunk_begin, chunk_end, item, + phrase_less_than<phrase_length>); + + const IndexItem * const begin = range.first; + const IndexItem * const end = range.second; + if (begin == end) + return result; + + const IndexItem * iter = NULL; + GArray * array = NULL; + + for (iter = begin; iter != end; ++iter) { + phrase_token_t token = iter->m_token; + + /* filter out disabled sub phrase indices. */ + array = tokens[PHRASE_INDEX_LIBRARY_INDEX(token)]; + if (NULL == array) + continue; + + result |= SEARCH_OK; + + g_array_append_val(array, token); + } + + return result; +} + |