diff options
Diffstat (limited to 'src/storage/ngram.cpp')
-rw-r--r-- | src/storage/ngram.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp index b8347d9..e4bfe8f 100644 --- a/src/storage/ngram.cpp +++ b/src/storage/ngram.cpp @@ -46,14 +46,12 @@ SingleGram::SingleGram(void * buffer, size_t length, bool copy){ } bool SingleGram::get_total_freq(guint32 & total) const{ - char * buf_begin = (char *)m_chunk.begin(); - total = *((guint32 *)buf_begin); + total = m_chunk.get_content<guint32>(0); return true; } bool SingleGram::set_total_freq(guint32 total){ - char * buf_begin = (char *)m_chunk.begin(); - *((guint32 *)buf_begin) = total; + m_chunk.set_content<guint32>(0, total); return true; } @@ -68,7 +66,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 +77,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,12 +98,12 @@ 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; } bool SingleGram::prune(){ - assert(false); + abort(); #if 0 SingleGramItem * begin = (SingleGramItem *) ((const char *)(m_chunk.begin()) + sizeof(guint32)); @@ -122,8 +120,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 +138,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 +162,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; @@ -283,15 +281,17 @@ bool merge_single_gram(SingleGram * merged, const SingleGram * system, MemoryChunk & merged_chunk = merged->m_chunk; + merged_chunk.set_size(0); + if (NULL == system) { - merged_chunk.set_chunk(user->m_chunk.begin(), - user->m_chunk.size(), NULL); + merged_chunk.set_content(0, user->m_chunk.begin(), + user->m_chunk.size()); return true; } if (NULL == user) { - merged_chunk.set_chunk(system->m_chunk.begin(), - system->m_chunk.size(), NULL); + merged_chunk.set_content(0, system->m_chunk.begin(), + system->m_chunk.size()); return true; } @@ -300,8 +300,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)); |