summaryrefslogtreecommitdiffstats
path: root/src/storage/pinyin_phrase2.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-17 18:16:54 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-17 18:16:54 +0800
commit3bcf118aab782f221185099de58de460c5d03077 (patch)
tree08ebb995a37ae857c55ffef8830efdcf9cea6611 /src/storage/pinyin_phrase2.h
parent38270cf002fa0ca6ba03d895c91487c940206f53 (diff)
downloadlibpinyin-3bcf118aab782f221185099de58de460c5d03077.tar.gz
libpinyin-3bcf118aab782f221185099de58de460c5d03077.tar.xz
libpinyin-3bcf118aab782f221185099de58de460c5d03077.zip
add phrase compare2
Diffstat (limited to 'src/storage/pinyin_phrase2.h')
-rw-r--r--src/storage/pinyin_phrase2.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h
index da8326d..d927ed9 100644
--- a/src/storage/pinyin_phrase2.h
+++ b/src/storage/pinyin_phrase2.h
@@ -22,6 +22,7 @@
#ifndef PINYIN_PHRASE2_H
#define PINYIN_PHRASE2_H
+#include "novel_types.h"
#include "chewing_key.h"
#include "pinyin_custom2.h"
#include "pinyin_parser2.h"
@@ -216,6 +217,36 @@ inline void compute_upper_value2(guint32 options,
}
}
+
+template<size_t phrase_length>
+struct PinyinIndexItem2{
+ phrase_token_t m_token;
+ ChewingKey m_keys[phrase_length];
+public:
+ PinyinIndexItem2<phrase_length> (ChewingKey * keys, phrase_token_t token) {
+ memmove(m_keys, keys, sizeof(ChewingKey) * phrase_length);
+ m_token = token;
+ }
+};
+
+
+/* for find the element in the phrase array */
+template<int phrase_length>
+inline int phrase_exact_compare2(const PinyinIndexItem2<phrase_length> &lhs,
+ const PinyinIndexItem2<phrase_length> &rhs)
+{
+ ChewingKey * keys_lhs = (ChewingKey *) lhs.m_keys;
+ ChewingKey * keys_rhs = (ChewingKey *) rhs.m_keys;
+ return pinyin_exact_compare2(keys_lhs, keys_rhs, phrase_length);
+}
+
+template<int phrase_length>
+inline bool phrase_exact_less_than2(const PinyinIndexItem2<phrase_length> &lhs,
+ const PinyinIndexItem2<phrase_length> &rhs)
+{
+ return 0 > phrase_exact_compare2<phrase_length>(lhs, rhs);
+}
+
};
#endif