From fb29787830eb012a92d5c4c0bde18a4228ee4a83 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 21 Aug 2012 14:00:14 +0800 Subject: [PATCH] write PhraseIndexItem --- src/storage/phrase_large_table2.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 -class PhraseArrayIndexLevel{ +class PhraseArrayIndexLevel2{ protected: MemoryChunk m_chunk; public: @@ -69,3 +69,31 @@ public: }; using namespace pinyin; + +/* class implementation */ + +template +struct PhraseIndexItem{ + phrase_token_t m_token; + ucs4_t m_phrase[phrase_length]; +public: + PhraseIndexItem(ucs4_t phrase[], phrase_token_t token){ + memmove(m_phrase, phrase, sizeof(ucs4_t) * phrase_length); + m_token = token; + } +}; + +template +static int phrase_compare(const PhraseIndexItem &lhs, + const PhraseIndexItem &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 +static bool phrase_less_than(const PhraseIndexItem & lhs, + const PhraseIndexItem & rhs){ + return 0 > phrase_compare(lhs, rhs); +} -- 2.7.4