3 * Library to deal with pinyin.
5 * Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef CHEWING_LARGE_TABLE_H
23 #define CHEWING_LARGE_TABLE_H
26 #include "novel_types.h"
27 #include "memory_chunk.h"
28 #include "chewing_key.h"
32 class ChewingLengthIndexLevel;
34 class ChewingBitmapIndexLevel{
37 pinyin_option_t m_options;
40 ChewingLengthIndexLevel * m_chewing_length_indexes
41 [CHEWING_NUMBER_OF_INITIALS][CHEWING_NUMBER_OF_MIDDLES]
42 [CHEWING_NUMBER_OF_FINALS][CHEWING_NUMBER_OF_TONES];
44 /* search functions */
45 int initial_level_search(int phrase_length, /* in */ ChewingKey keys[],
46 /* out */ PhraseIndexRanges ranges) const;
48 int middle_and_final_level_search(ChewingInitial initial,
50 /* in */ ChewingKey keys[],
51 /* out */ PhraseIndexRanges ranges) const;
52 int tone_level_search(ChewingInitial initial, ChewingMiddle middle,
53 ChewingFinal final, int phrase_length,
54 /* in */ ChewingKey keys[],
55 /* out */ PhraseIndexRanges ranges) const;
60 /* constructor/destructor */
61 ChewingBitmapIndexLevel(pinyin_option_t options);
62 ~ChewingBitmapIndexLevel() { reset(); }
64 /* set options method */
65 bool set_options(pinyin_option_t options) {
70 /* load/store method */
71 bool load(MemoryChunk * chunk, table_offset_t offset, table_offset_t end);
72 bool store(MemoryChunk * new_chunk, table_offset_t offset,
73 table_offset_t & end);
76 int search(int phrase_length, /* in */ ChewingKey keys[],
77 /* out */ PhraseIndexRanges ranges) const;
79 /* add/remove index method */
80 int add_index(int phrase_length, /* in */ ChewingKey keys[],
81 /* in */ phrase_token_t token);
82 int remove_index(int phrase_length, /* in */ ChewingKey keys[],
83 /* in */ phrase_token_t token);
86 bool mask_out(phrase_token_t mask, phrase_token_t value);
90 class ChewingLargeTable{
92 ChewingBitmapIndexLevel m_bitmap_table;
93 MemoryChunk * m_chunk;
97 delete m_chunk; m_chunk = NULL;
102 /* constructor/destructor */
103 ChewingLargeTable(pinyin_option_t options):
104 m_bitmap_table(options), m_chunk(NULL) {}
106 ~ChewingLargeTable() { reset(); }
108 /* set options method */
109 bool set_options(pinyin_option_t options) {
110 return m_bitmap_table.set_options(options);
113 /* load/store method */
114 bool load(MemoryChunk * chunk) {
117 return m_bitmap_table.load(chunk, 0, chunk->size());
120 bool store(MemoryChunk * new_chunk) {
122 return m_bitmap_table.store(new_chunk, 0, end);
125 bool load_text(FILE * file);
128 int search(int phrase_length, /* in */ ChewingKey keys[],
129 /* out */ PhraseIndexRanges ranges) const {
130 return m_bitmap_table.search(phrase_length, keys, ranges);
133 /* add/remove index method */
134 int add_index(int phrase_length, /* in */ ChewingKey keys[],
135 /* in */ phrase_token_t token) {
136 return m_bitmap_table.add_index(phrase_length, keys, token);
139 int remove_index(int phrase_length, /* in */ ChewingKey keys[],
140 /* in */ phrase_token_t token) {
141 return m_bitmap_table.remove_index(phrase_length, keys, token);
144 /* mask out method */
145 bool mask_out(phrase_token_t mask, phrase_token_t value) {
146 return m_bitmap_table.mask_out(mask, value);