write PhraseIndexItem
authorPeng Wu <alexepico@gmail.com>
Tue, 21 Aug 2012 06:00:14 +0000 (14:00 +0800)
committerPeng Wu <alexepico@gmail.com>
Sat, 25 Aug 2012 05:28:21 +0000 (13:28 +0800)
src/storage/phrase_large_table2.cpp

index b87fb40f3dbde9ca57d0321c4c51f410acbcd41e..5eb1c18c829667d81c3a0871c27d89c80bb6c348 100644 (file)
@@ -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);
+}