From 457445fdc6cd0e5446665ec05a8fe25d6d9d49eb Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 27 Aug 2012 16:08:58 +0800 Subject: write search method --- src/storage/phrase_large_table2.cpp | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/storage/phrase_large_table2.cpp') 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 +int PhraseArrayIndexLevel2::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 range; + range = std_lite::equal_range + (chunk_begin, chunk_end, item, + phrase_less_than); + + 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; +} + -- cgit