summaryrefslogtreecommitdiffstats
path: root/src/lookup/pinyin_lookup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lookup/pinyin_lookup.cpp')
-rw-r--r--src/lookup/pinyin_lookup.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lookup/pinyin_lookup.cpp b/src/lookup/pinyin_lookup.cpp
index c32e2bb..d6ba68c 100644
--- a/src/lookup/pinyin_lookup.cpp
+++ b/src/lookup/pinyin_lookup.cpp
@@ -108,18 +108,27 @@ bool PinyinLookup::destroy_pinyin_lookup(PhraseIndexRanges ranges){
}
size_t PinyinLookup::prepare_table_cache(int nstep, int total_pinyin){
- //free resources
+ /* free resources */
for ( size_t i = 0; i < m_table_cache->len; ++i){
PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, i);
destroy_pinyin_lookup(*ranges);
}
- //g_array_set_size(m_table_cache, 1);
+
PinyinKey * pinyin_keys = (PinyinKey *)m_keys->data;
pinyin_keys += nstep;
- //init resources
g_array_set_size(m_table_cache, MAX_PHRASE_LENGTH + 1);
- int len;
- for ( len = 1; len <= total_pinyin && len <= MAX_PHRASE_LENGTH; ++len){
+
+ int len, total_len = std::min(total_pinyin, MAX_PHRASE_LENGTH);
+
+ /* probe constraint */
+ for ( len = 1; len <= total_len; ++len) {
+ lookup_constraint_t * constraint = &g_array_index(m_constraints, lookup_constraint_t, nstep + len);
+ if (constraint->m_type == CONSTRAINT_ONESTEP)
+ break;
+ }
+ total_len = std::min(len, total_len);
+
+ for ( len = 1; len <= total_len; ++len){
PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, len);
prepare_pinyin_lookup(*ranges);
int result = m_pinyin_table->search(len, pinyin_keys, *ranges);