From ad4e7289182d50ebd7fb040fa180a0c4b54473f6 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 21 Aug 2012 11:29:06 +0800 Subject: add phrase_large_table2.cpp --- src/storage/phrase_large_table2.cpp | 71 +++++++++++++++++++++++++++++++++++++ src/storage/phrase_large_table2.h | 8 ++--- 2 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 src/storage/phrase_large_table2.cpp diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp new file mode 100644 index 0000000..b87fb40 --- /dev/null +++ b/src/storage/phrase_large_table2.cpp @@ -0,0 +1,71 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2012 Peng Wu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include "phrase_large_table2.h" + + +/* class definition */ + +namespace pinyin{ + +class PhraseLengthIndexLevel2{ +protected: + GArray * m_phrase_array_indexes; +public: + PhraseLengthIndexLevel2(); + ~PhraseLengthIndexLevel2(); + + /* 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(int phrase_length, /* in */ ucs4_t phrase[], + /* out */ PhraseTokens tokens); + + /* add_index/remove_index method */ + int add_index(int phrase_length, /* in */ ucs4_t phrase[], + /* in */ phrase_token_t token); + int remove_index(int phrase_length, /* in */ ucs4_t phrase[], + /* in */ phrase_token_t token); +}; + +template +class PhraseArrayIndexLevel{ +protected: + MemoryChunk m_chunk; +public: + 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(/* in */ ucs4_t phrase[], /* out */ PhraseTokens tokens); + + /* add_index/remove_index method */ + int add_index(/* in */ ucs4_t phrase[], /* in */ phrase_token_t token); + int remove_index(/* in */ ucs4_t phrase[], /* in */ phrase_token_t token); +}; + +}; + +using namespace pinyin; diff --git a/src/storage/phrase_large_table2.h b/src/storage/phrase_large_table2.h index 314962c..32f4934 100644 --- a/src/storage/phrase_large_table2.h +++ b/src/storage/phrase_large_table2.h @@ -45,7 +45,7 @@ public: /* load/store method */ bool load(MemoryChunk * chunk, table_offset_t offset, table_offset_t end); - bool store(MemoryChunk * newchunk, 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(int phrase_length, /* in */ ucs4_t phrase[], @@ -85,9 +85,9 @@ public: return m_bitmap_table.load(chunk, 0, chunk->size()); } - bool store(MemoryChunk * newchunk){ + bool store(MemoryChunk * new_chunk){ table_offset_t end; - return m_bitmap_table.store(newchunk, 0, end); + return m_bitmap_table.store(new_chunk, 0, end); } bool load_text(FILE * file); @@ -103,7 +103,7 @@ public: return m_bitmap_table.add_index(phrase_length, phrase, token); } - int remove_index(int phrase_length, /* in */ ucs4_t phrase[], /* out */ phrase_token_t token) { + int remove_index(int phrase_length, /* in */ ucs4_t phrase[], /* in */ phrase_token_t token) { return m_bitmap_table.remove_index(phrase_length, phrase, token); } }; -- cgit