summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-08-21 14:00:14 +0800
committerPeng Wu <alexepico@gmail.com>2012-08-25 13:28:21 +0800
commitfb29787830eb012a92d5c4c0bde18a4228ee4a83 (patch)
treee08fbf5eb74fe603c2303140003ffaa03397e4a5
parent400c0c6f7d52d4f112a4cb418326374819d924a6 (diff)
downloadlibpinyin-fb29787830eb012a92d5c4c0bde18a4228ee4a83.tar.gz
libpinyin-fb29787830eb012a92d5c4c0bde18a4228ee4a83.tar.xz
libpinyin-fb29787830eb012a92d5c4c0bde18a4228ee4a83.zip
write PhraseIndexItem
-rw-r--r--src/storage/phrase_large_table2.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp
index b87fb40..5eb1c18 100644
--- a/src/storage/phrase_large_table2.cpp
+++ b/src/storage/phrase_large_table2.cpp
@@ -51,7 +51,7 @@ public:
};
template<size_t phrase_length>
-class PhraseArrayIndexLevel{
+class PhraseArrayIndexLevel2{
protected:
MemoryChunk m_chunk;
public:
@@ -69,3 +69,31 @@ public:
};
using namespace pinyin;
+
+/* class implementation */
+
+template<size_t phrase_length>
+struct PhraseIndexItem{
+ phrase_token_t m_token;
+ ucs4_t m_phrase[phrase_length];
+public:
+ PhraseIndexItem<phrase_length>(ucs4_t phrase[], phrase_token_t token){
+ memmove(m_phrase, phrase, sizeof(ucs4_t) * phrase_length);
+ m_token = token;
+ }
+};
+
+template<size_t phrase_length>
+static int phrase_compare(const PhraseIndexItem<phrase_length> &lhs,
+ const PhraseIndexItem<phrase_length> &rhs){
+ ucs4_t * phrase_lhs = (ucs4_t *) lhs.m_phrase;
+ ucs4_t * phrase_rhs = (ucs4_t *) rhs.m_phrase;
+
+ return memcmp(phrase_lhs, phrase_rhs, sizeof(ucs4_t) * phrase_length);
+}
+
+template<size_t phrase_length>
+static bool phrase_less_than(const PhraseIndexItem<phrase_length> & lhs,
+ const PhraseIndexItem<phrase_length> & rhs){
+ return 0 > phrase_compare(lhs, rhs);
+}