summaryrefslogtreecommitdiffstats
path: root/src/pinyin.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-07-02 12:02:31 +0800
committerPeng Wu <alexepico@gmail.com>2012-07-02 12:02:31 +0800
commit38d497bf3263ce67d6085283407189aa293bd843 (patch)
tree3888d9aea3676363b53258e91651745c8ab95e16 /src/pinyin.cpp
parentb1563019cb3cad50e93416e310e8ab2cdaa516b2 (diff)
downloadlibpinyin-38d497bf3263ce67d6085283407189aa293bd843.tar.gz
libpinyin-38d497bf3263ce67d6085283407189aa293bd843.tar.xz
libpinyin-38d497bf3263ce67d6085283407189aa293bd843.zip
fixes _remove_duplicated_items_by_phrase_string
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r--src/pinyin.cpp65
1 files changed, 35 insertions, 30 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 4b1b9ed..b0d9d23 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -969,40 +969,45 @@ static bool _remove_duplicated_items_by_phrase_string
/* mark duplicated items as zombie candidate */
lookup_candidate_t * cur_item, * saved_item = NULL;
- for (i = 0; i < candidates->len; ++i) {
- cur_item = &g_array_index(candidates, lookup_candidate_t, i);
- if (saved_item) {
- if (0 == strcmp(saved_item->m_phrase_string,
- cur_item->m_phrase_string)) {
- /* found duplicated candidates */
-
- /* keep best match candidate */
- if (BEST_MATCH_CANDIDATE == saved_item->m_candidate_type) {
- cur_item->m_candidate_type = ZOMBIE_CANDIDATE;
- continue;
- }
+ for (i = 0; i < indices->len; ++i) {
+ size_t cur_index = g_array_index(indices, size_t, i);
+ cur_item = &g_array_index(candidates, lookup_candidate_t, cur_index);
- if (BEST_MATCH_CANDIDATE == cur_item->m_candidate_type) {
- saved_item->m_candidate_type = ZOMBIE_CANDIDATE;
- saved_item = cur_item;
- continue;
- }
+ if (!saved_item) {
+ saved_item = cur_item;
+ continue;
+ }
- /* keep the higher possiblity one
- to quickly move the word forward in the candidate list */
- if (cur_item->m_freq > saved_item->m_freq) {
- /* find better candidate */
- saved_item->m_candidate_type = ZOMBIE_CANDIDATE;
- saved_item = cur_item;
- continue;
- } else {
- cur_item->m_candidate_type = ZOMBIE_CANDIDATE;
- continue;
- }
- } else {
- /* keep the current candidate */
+ if (0 == strcmp(saved_item->m_phrase_string,
+ cur_item->m_phrase_string)) {
+ /* found duplicated candidates */
+
+ /* keep best match candidate */
+ if (BEST_MATCH_CANDIDATE == saved_item->m_candidate_type) {
+ cur_item->m_candidate_type = ZOMBIE_CANDIDATE;
+ continue;
+ }
+
+ if (BEST_MATCH_CANDIDATE == cur_item->m_candidate_type) {
+ saved_item->m_candidate_type = ZOMBIE_CANDIDATE;
saved_item = cur_item;
+ continue;
}
+
+ /* keep the higher possiblity one
+ to quickly move the word forward in the candidate list */
+ if (cur_item->m_freq > saved_item->m_freq) {
+ /* find better candidate */
+ saved_item->m_candidate_type = ZOMBIE_CANDIDATE;
+ saved_item = cur_item;
+ continue;
+ } else {
+ cur_item->m_candidate_type = ZOMBIE_CANDIDATE;
+ continue;
+ }
+ } else {
+ /* keep the current candidate */
+ saved_item = cur_item;
}
}