diff options
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/chewing_large_table.h | 1 | ||||
-rw-r--r-- | src/storage/chewing_large_table2_kyotodb.cpp | 10 | ||||
-rw-r--r-- | src/storage/flexible_ngram.h | 1 | ||||
-rw-r--r-- | src/storage/flexible_ngram_kyotodb.h | 8 | ||||
-rw-r--r-- | src/storage/ngram.cpp | 28 | ||||
-rw-r--r-- | src/storage/ngram.h | 1 | ||||
-rw-r--r-- | src/storage/ngram_bdb.cpp | 8 | ||||
-rw-r--r-- | src/storage/ngram_kyotodb.cpp | 10 | ||||
-rw-r--r-- | src/storage/phrase_large_table3.h | 1 | ||||
-rw-r--r-- | src/storage/phrase_large_table3_kyotodb.cpp | 10 |
10 files changed, 41 insertions, 37 deletions
diff --git a/src/storage/chewing_large_table.h b/src/storage/chewing_large_table.h index d836769..21158e1 100644 --- a/src/storage/chewing_large_table.h +++ b/src/storage/chewing_large_table.h @@ -26,6 +26,7 @@ #include "novel_types.h" #include "memory_chunk.h" #include "chewing_key.h" +#include "pinyin_utils.h" #include "table_info.h" namespace pinyin{ diff --git a/src/storage/chewing_large_table2_kyotodb.cpp b/src/storage/chewing_large_table2_kyotodb.cpp index ef3bcbe..e57552c 100644 --- a/src/storage/chewing_large_table2_kyotodb.cpp +++ b/src/storage/chewing_large_table2_kyotodb.cpp @@ -30,7 +30,7 @@ namespace pinyin{ ChewingLargeTable2::ChewingLargeTable2() { /* create in-memory db. */ m_db = new ProtoTreeDB; - assert(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE)); + check_result(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE)); m_entries = NULL; init_entries(); @@ -144,8 +144,8 @@ int ChewingLargeTable2::search_internal(/* in */ const ChewingKey index[], entry->m_chunk.set_size(vsiz); /* m_chunk may re-allocate here. */ char * vbuf = (char *) entry->m_chunk.begin(); - assert(vsiz == m_db->get(kbuf, phrase_length * sizeof(ChewingKey), - vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, phrase_length * sizeof(ChewingKey), + vbuf, vsiz)); result = entry->search(keys, ranges) | result; @@ -236,7 +236,7 @@ int ChewingLargeTable2::add_index_internal(/* in */ const ChewingKey index[], entry->m_chunk.set_size(vsiz); /* m_chunk may re-allocate here. */ vbuf = (char *) entry->m_chunk.begin(); - assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); int result = entry->add_index(keys, token); @@ -305,7 +305,7 @@ int ChewingLargeTable2::remove_index_internal(/* in */ const ChewingKey index[], entry->m_chunk.set_size(vsiz); /* m_chunk may re-allocate here. */ vbuf = (char *) entry->m_chunk.begin(); - assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); int result = entry->remove_index(keys, token); if (ERROR_OK != result) diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h index f6b0161..a80baa3 100644 --- a/src/storage/flexible_ngram.h +++ b/src/storage/flexible_ngram.h @@ -28,6 +28,7 @@ * struct MagicHeader, ArrayHeader, ArrayItem. */ +#include "pinyin_utils.h" #include "flexible_single_gram.h" #ifdef HAVE_BERKELEY_DB diff --git a/src/storage/flexible_ngram_kyotodb.h b/src/storage/flexible_ngram_kyotodb.h index ad84b78..b12fa42 100644 --- a/src/storage/flexible_ngram_kyotodb.h +++ b/src/storage/flexible_ngram_kyotodb.h @@ -171,7 +171,7 @@ public: m_chunk.set_size(vsiz); char * vbuf = (char *) m_chunk.begin(); - assert (vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); if ( memcmp(vbuf, m_magic_number, sizeof(m_magic_number)) == 0 ) @@ -206,8 +206,8 @@ public: m_chunk.set_size(vsiz); char * vbuf = (char *) m_chunk.begin(); - assert (vsiz == m_db->get(kbuf, sizeof(phrase_token_t), - vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, sizeof(phrase_token_t), + vbuf, vsiz)); single_gram = new FlexibleSingleGram<ArrayHeader, ArrayItem> (m_chunk.begin(), vsiz, copy); @@ -397,7 +397,7 @@ public: } else { /* found */ m_chunk.set_size(vsiz); char * vbuf = (char *) m_chunk.begin(); - assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); } m_chunk.set_content(0, &header, sizeof(ArrayHeader)); diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp index f2e0aa3..ca845c5 100644 --- a/src/storage/ngram.cpp +++ b/src/storage/ngram.cpp @@ -68,7 +68,7 @@ guint32 SingleGram::get_length(){ if (0 == length) { /* no items here, total freq should be zero. */ guint32 total_freq = 0; - assert(get_total_freq(total_freq)); + check_result(get_total_freq(total_freq)); assert(0 == total_freq); } @@ -79,7 +79,7 @@ guint32 SingleGram::mask_out(phrase_token_t mask, phrase_token_t value){ guint32 removed_items = 0; guint32 total_freq = 0; - assert(get_total_freq(total_freq)); + check_result(get_total_freq(total_freq)); const SingleGramItem * begin = (const SingleGramItem *) ((const char *)(m_chunk.begin()) + sizeof(guint32)); @@ -100,7 +100,7 @@ guint32 SingleGram::mask_out(phrase_token_t mask, phrase_token_t value){ --cur; } - assert(set_total_freq(total_freq)); + check_result(set_total_freq(total_freq)); return removed_items; } @@ -122,8 +122,8 @@ bool SingleGram::prune(){ } } guint32 total_freq; - assert(get_total_freq(total_freq)); - assert(set_total_freq(total_freq - nitem)); + check_result(get_total_freq(total_freq)); + check_result(set_total_freq(total_freq - nitem)); #endif return true; } @@ -140,7 +140,7 @@ bool SingleGram::retrieve_all(/* out */ BigramPhraseWithCountArray array) guint32 total_freq; BigramPhraseItemWithCount bigram_item_with_count; - assert(get_total_freq(total_freq)); + check_result(get_total_freq(total_freq)); for ( const SingleGramItem * cur_item = begin; cur_item != end; ++cur_item){ bigram_item_with_count.m_token = cur_item->m_token; @@ -164,14 +164,14 @@ bool SingleGram::search(/* in */ PhraseIndexRange * range, guint32 total_freq; BigramPhraseItem bigram_item; - assert(get_total_freq(total_freq)); + check_result(get_total_freq(total_freq)); for ( ; cur_item != end; ++cur_item){ - if ( cur_item->m_token >= range->m_range_end ) - break; - bigram_item.m_token = cur_item->m_token; - bigram_item.m_freq = cur_item->m_freq / (gfloat)total_freq; - g_array_append_val(array, bigram_item); + if ( cur_item->m_token >= range->m_range_end ) + break; + bigram_item.m_token = cur_item->m_token; + bigram_item.m_freq = cur_item->m_freq / (gfloat)total_freq; + g_array_append_val(array, bigram_item); } return true; @@ -302,8 +302,8 @@ bool merge_single_gram(SingleGram * merged, const SingleGram * system, /* merge the origin info and delta info */ guint32 system_total, user_total; - assert(system->get_total_freq(system_total)); - assert(user->get_total_freq(user_total)); + check_result(system->get_total_freq(system_total)); + check_result(user->get_total_freq(user_total)); const guint32 merged_total = system_total + user_total; merged_chunk.set_content(0, &merged_total, sizeof(guint32)); diff --git a/src/storage/ngram.h b/src/storage/ngram.h index 7f7a653..57979b4 100644 --- a/src/storage/ngram.h +++ b/src/storage/ngram.h @@ -24,6 +24,7 @@ #include "config.h" #include <glib.h> #include "novel_types.h" +#include "pinyin_utils.h" #ifdef HAVE_BERKELEY_DB #include "ngram_bdb.h" diff --git a/src/storage/ngram_bdb.cpp b/src/storage/ngram_bdb.cpp index 95afdbd..8910f9d 100644 --- a/src/storage/ngram_bdb.cpp +++ b/src/storage/ngram_bdb.cpp @@ -227,12 +227,12 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){ phrase_token_t index = g_array_index(items, phrase_token_t, i); if ((index & mask) == value) { - assert(remove(index)); + check_result(remove(index)); continue; } SingleGram * gram = NULL; - assert(load(index, gram)); + check_result(load(index, gram)); int num = gram->mask_out(mask, value); if (0 == num) { @@ -241,9 +241,9 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){ } if (0 == gram->get_length()) { - assert(remove(index)); + check_result(remove(index)); } else { - assert(store(index, gram)); + check_result(store(index, gram)); } delete gram; diff --git a/src/storage/ngram_kyotodb.cpp b/src/storage/ngram_kyotodb.cpp index 54c2055..560e196 100644 --- a/src/storage/ngram_kyotodb.cpp +++ b/src/storage/ngram_kyotodb.cpp @@ -133,7 +133,7 @@ bool Bigram::load(phrase_token_t index, SingleGram * & single_gram, m_chunk.set_size(vsiz); char * vbuf = (char *) m_chunk.begin(); - assert (vsiz == m_db->get(kbuf, sizeof(phrase_token_t), + check_result (vsiz == m_db->get(kbuf, sizeof(phrase_token_t), vbuf, vsiz)); single_gram = new SingleGram(m_chunk.begin(), vsiz, copy); @@ -206,12 +206,12 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){ phrase_token_t index = g_array_index(items, phrase_token_t, i); if ((index & mask) == value) { - assert(remove(index)); + check_result(remove(index)); continue; } SingleGram * gram = NULL; - assert(load(index, gram)); + check_result(load(index, gram)); int num = gram->mask_out(mask, value); if (0 == num) { @@ -220,9 +220,9 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){ } if (0 == gram->get_length()) { - assert(remove(index)); + check_result(remove(index)); } else { - assert(store(index, gram)); + check_result(store(index, gram)); } delete gram; diff --git a/src/storage/phrase_large_table3.h b/src/storage/phrase_large_table3.h index 2774767..40654bb 100644 --- a/src/storage/phrase_large_table3.h +++ b/src/storage/phrase_large_table3.h @@ -24,6 +24,7 @@ #include <stdio.h> #include "novel_types.h" #include "memory_chunk.h" +#include "pinyin_utils.h" #ifdef HAVE_BERKELEY_DB #include "phrase_large_table3_bdb.h" diff --git a/src/storage/phrase_large_table3_kyotodb.cpp b/src/storage/phrase_large_table3_kyotodb.cpp index 73e578c..571f97c 100644 --- a/src/storage/phrase_large_table3_kyotodb.cpp +++ b/src/storage/phrase_large_table3_kyotodb.cpp @@ -31,7 +31,7 @@ namespace pinyin{ PhraseLargeTable3::PhraseLargeTable3() { /* create in-memory db. */ m_db = new ProtoTreeDB; - assert(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE)); + check_result(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE)); m_entry = new PhraseTableEntry; } @@ -147,8 +147,8 @@ int PhraseLargeTable3::search(int phrase_length, m_entry->m_chunk.set_size(vsiz); /* m_chunk may re-allocate here. */ char * vbuf = (char *) m_entry->m_chunk.begin(); - assert (vsiz == m_db->get(kbuf, phrase_length * sizeof(ucs4_t), - vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, phrase_length * sizeof(ucs4_t), + vbuf, vsiz)); result = m_entry->search(tokens) | result; @@ -202,7 +202,7 @@ int PhraseLargeTable3::add_index(int phrase_length, m_entry->m_chunk.set_size(vsiz); /* m_chunk may re-allocate here. */ vbuf = (char *) m_entry->m_chunk.begin(); - assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); int result = m_entry->add_index(token); @@ -233,7 +233,7 @@ int PhraseLargeTable3::remove_index(int phrase_length, m_entry->m_chunk.set_size(vsiz); /* m_chunk may re-allocate here. */ vbuf = (char *) m_entry->m_chunk.begin(); - assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); + check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz)); int result = m_entry->remove_index(token); if (ERROR_OK != result) |