summaryrefslogtreecommitdiffstats
path: root/src/storage/chewing_large_table2.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-03-14 13:48:07 +0800
committerPeng Wu <alexepico@gmail.com>2016-03-14 13:48:07 +0800
commitc8068ec8520d3ab1f34b7e55c9238827d8d56a68 (patch)
treeeef9153298aa2278ba7e18532f5c095483c4fd50 /src/storage/chewing_large_table2.cpp
parent312eb6bb3212ed3aceef1daaadfe3e7d5554c95a (diff)
downloadlibpinyin-c8068ec8520d3ab1f34b7e55c9238827d8d56a68.tar.gz
libpinyin-c8068ec8520d3ab1f34b7e55c9238827d8d56a68.tar.xz
libpinyin-c8068ec8520d3ab1f34b7e55c9238827d8d56a68.zip
re-factor code
Diffstat (limited to 'src/storage/chewing_large_table2.cpp')
-rw-r--r--src/storage/chewing_large_table2.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/storage/chewing_large_table2.cpp b/src/storage/chewing_large_table2.cpp
index 2376a5c..7f49772 100644
--- a/src/storage/chewing_large_table2.cpp
+++ b/src/storage/chewing_large_table2.cpp
@@ -23,6 +23,90 @@
#include "pinyin_parser2.h"
+void ChewingLargeTable2::init_entries() {
+ assert(NULL == m_entries);
+
+ m_entries = g_ptr_array_new();
+ /* NULL for the first pointer. */
+ g_ptr_array_set_size(m_entries, MAX_PHRASE_LENGTH + 1);
+
+#define CASE(len) case len: \
+ { \
+ ChewingTableEntry<len> * entry = \
+ new ChewingTableEntry<len>; \
+ g_ptr_array_index(m_entries, len) = entry; \
+ }
+
+ for (size_t i = 1; i < m_entries->len; i++) {
+ switch(i) {
+ CASE(1);
+ CASE(2);
+ CASE(3);
+ CASE(4);
+ CASE(5);
+ CASE(6);
+ CASE(7);
+ CASE(8);
+ CASE(9);
+ CASE(10);
+ CASE(11);
+ CASE(12);
+ CASE(13);
+ CASE(14);
+ CASE(15);
+ CASE(16);
+ default:
+ assert(false);
+ }
+ }
+
+#undef CASE
+}
+
+void ChewingLargeTable2::fini_entries() {
+ assert(NULL != m_entries);
+
+ assert(MAX_PHRASE_LENGTH + 1 == m_entries->len);
+
+ for (size_t i = 1; i < m_entries->len; i++) {
+
+#define CASE(len) case len: \
+ { \
+ ChewingTableEntry<len> * entry = \
+ (ChewingTableEntry<len> *) \
+ g_ptr_array_index(m_entries, len); \
+ delete entry; \
+ }
+
+ switch(i) {
+ CASE(1);
+ CASE(2);
+ CASE(3);
+ CASE(4);
+ CASE(5);
+ CASE(6);
+ CASE(7);
+ CASE(8);
+ CASE(9);
+ CASE(10);
+ CASE(11);
+ CASE(12);
+ CASE(13);
+ CASE(14);
+ CASE(15);
+ CASE(16);
+ default:
+ assert(false);
+ }
+
+#undef CASE
+
+ }
+
+ g_ptr_array_free(m_entries, TRUE);
+ m_entries = NULL;
+}
+
/* load text method */
bool ChewingLargeTable2::load_text(FILE * infile) {
char pinyin[256];