From 1eacb0a42d5c7263369fb1f712506aa28d0c37f7 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 29 Nov 2011 16:31:08 +0800 Subject: write chewing large table in progress --- src/storage/chewing_large_table.cpp | 69 +++++++++++++++++++++++++++++++++++++ src/storage/chewing_large_table.h | 11 ++++++ 2 files changed, 80 insertions(+) diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index aec2b71..db803ec 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -20,3 +20,72 @@ */ #include "chewing_large_table.h" +#include +#include "pinyin_phrase2.h" + + +/* internal class definition */ + +namespace pinyin{ +class ChewingLengthIndexLevel{ + +protected: + GArray * m_chewing_array_indexes; + +public: + /* constructor/destructor */ + ChewingLengthIndexLevel(); + ~ChewingLengthIndexLevel(); + + /* load/store method */ + bool load(MemoryChunk * chunk, table_offset_t offset, table_offset_t end); + bool store(MemoryChunk * new_chunk, table_offset_t offset, + table_offset_t & end); + + /* search method */ + int search(pinyin_option_t options, int phrase_length, + /* in */ ChewingKey keys[], + /* out */ PhraseIndexRanges ranges); + + /* add/remove index method */ + int add_index(int phrase_length, /* in */ ChewingKey keys[], + /* in */ phrase_token_t token); + int remove_index(int phrase_length, /* in */ ChewingKey keys[], + /* in */ phrase_token_t token); +}; + + +template +class ChewingArrayIndexLevel{ +protected: + MemoryChunk m_chunk; + + /* compress consecutive tokens */ + int convert(pinyin_option_t options, + ChewingKey keys[], + PinyinIndexItem2 * begin, + PinyinIndexItem2 * end, + PhraseIndexRanges ranges); + +public: + /* load/store method */ + bool load(MemoryChunk * chunk, table_offset_t offset, table_offset_t end); + bool store(MemoryChunk * new_chunk, table_offset_t offset, + table_offset_t & end); + + /* search method */ + int search(pinyin_option_t options, /* in */ChewingKey keys[], + /* out */ PhraseIndexRanges ranges); + + /* add/remove index method */ + int add_index(/* in */ ChewingKey keys[], /* in */ phrase_token_t token); + int remove_index(/* in */ ChewingKey keys[], + /* in */ phrase_token_t token); +}; + +}; + + +using namespace pinyin; + +/* class implementation */ diff --git a/src/storage/chewing_large_table.h b/src/storage/chewing_large_table.h index 52ee01b..071101f 100644 --- a/src/storage/chewing_large_table.h +++ b/src/storage/chewing_large_table.h @@ -56,6 +56,12 @@ public: ChewingBitmapIndexLevel(pinyin_option_t options) : m_options(options){} ~ChewingBitmapIndexLevel() { reset(); } + /* set options method */ + bool set_options(pinyin_option_t options) { + m_options = options; + return true; + } + /* load/store method */ bool load(MemoryChunk * chunk, table_offset_t offset, table_offset_t end); bool store(MemoryChunk * new_chunk, table_offset_t offset, @@ -91,6 +97,11 @@ public: ~ChewingLargeTable() { reset(); } + /* set options method */ + bool set_options(pinyin_option_t options) { + return m_bitmap_table.set_options(options); + } + /* load/store method */ bool load(MemoryChunk * chunk) { reset(); -- cgit