summaryrefslogtreecommitdiffstats
path: root/src/storage/pinyin_phrase3.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-02-24 14:10:08 +0800
committerPeng Wu <alexepico@gmail.com>2016-02-24 14:10:08 +0800
commit72fe72ed62a55d8ed13e012c13acfae3e9de2e67 (patch)
treeea4ecc708582939c523266cfe99e88240222d6c2 /src/storage/pinyin_phrase3.h
parent3636f34f41b174fb34bf9331bb742a9d7bc4d4fb (diff)
downloadlibpinyin-72fe72ed62a55d8ed13e012c13acfae3e9de2e67.tar.gz
libpinyin-72fe72ed62a55d8ed13e012c13acfae3e9de2e67.tar.xz
libpinyin-72fe72ed62a55d8ed13e012c13acfae3e9de2e67.zip
write pinyin_compare_with_tones function
Diffstat (limited to 'src/storage/pinyin_phrase3.h')
-rw-r--r--src/storage/pinyin_phrase3.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/storage/pinyin_phrase3.h b/src/storage/pinyin_phrase3.h
index 051e24d..aa3dbd0 100644
--- a/src/storage/pinyin_phrase3.h
+++ b/src/storage/pinyin_phrase3.h
@@ -101,6 +101,44 @@ inline int pinyin_compare_tone3(ChewingTone lhs,
return (lhs - rhs);
}
+inline int pinyin_compare_with_tones(const ChewingKey * key_lhs,
+ const ChewingKey * key_rhs,
+ int phrase_length){
+ int i;
+ int result;
+
+ /* compare initial */
+ for (i = 0; i < phrase_length; ++i) {
+ result = pinyin_compare_initial3
+ ((ChewingInitial)key_lhs[i].m_initial,
+ (ChewingInitial)key_rhs[i].m_initial);
+ if (0 != result)
+ return result;
+ }
+
+ /* compare middle and final */
+ for (i = 0; i < phrase_length; ++i) {
+ result = pinyin_compare_middle_and_final3
+ ((ChewingMiddle)key_lhs[i].m_middle,
+ (ChewingMiddle)key_rhs[i].m_middle,
+ (ChewingFinal) key_lhs[i].m_final,
+ (ChewingFinal) key_rhs[i].m_final);
+ if (0 != result)
+ return result;
+ }
+
+ /* compare tone */
+ for (i = 0; i < phrase_length; ++i) {
+ result = pinyin_compare_tone3
+ ((ChewingTone)key_lhs[i].m_tone,
+ (ChewingTone)key_rhs[i].m_tone);
+ if (0 != result)
+ return result;
+ }
+
+ return 0;
+}
+
template<size_t phrase_length>
struct PinyinIndexItem2{