From 606b4b110302fad6590eca56cba7108681b8b434 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 21 Jun 2012 13:06:33 +0800 Subject: add ErrorResult --- src/include/novel_types.h | 25 +++---------------------- src/storage/chewing_large_table.cpp | 14 +++++++------- src/storage/phrase_large_table.cpp | 14 +++++++------- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/include/novel_types.h b/src/include/novel_types.h index de249ca..014c11a 100644 --- a/src/include/novel_types.h +++ b/src/include/novel_types.h @@ -73,19 +73,11 @@ enum SearchResult{ SEARCH_CONTINUED = 0x02 /* has longer word in the storage to search */ }; -enum AddIndexResult{ - INSERT_OK = 0 , /* insert ok */ - INSERT_ITEM_EXISTS /* item already exists */ -}; - -enum RemoveIndexResult{ - REMOVE_OK = 0, /* remove ok */ - REMOVE_ITEM_DONOT_EXISTS /* item don't exists */ -}; - /* For Phrase Index */ -enum PhraseIndexResult{ +enum ErrorResult{ ERROR_OK = 0, /* operate ok */ + ERROR_INSERT_ITEM_EXISTS, /* item already exists */ + ERROR_REMOVE_ITEM_DONOT_EXISTS, /* item don't exists */ ERROR_NO_SUB_PHRASE_INDEX, /* sub phrase index is not loaded */ ERROR_NO_ITEM, /* item has a null slot */ ERROR_OUT_OF_RANGE, /* beyond the end of the sub phrase index */ @@ -122,17 +114,6 @@ struct BigramPhraseItemWithCount{ typedef GArray * BigramPhraseArray; /* Array of BigramPhraseItem */ typedef GArray * BigramPhraseWithCountArray; /* Array of BigramPhraseItemWithCount */ -/* - * n-gram Definition - * n-gram library - */ - -enum AttachOption{ - ATTACH_NEW_FILE = 1, - ATTACH_READ = 2, - ATTACH_READ_WRITE = 3 -}; - #define MAX_PHRASE_LENGTH 16 const phrase_token_t null_token = 0; diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index cfcb987..9185976 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -484,7 +484,7 @@ int ChewingBitmapIndexLevel::remove_index(int phrase_length, if (length_array) return length_array->remove_index(phrase_length - 1, keys + 1, token); - return REMOVE_ITEM_DONOT_EXISTS; + return ERROR_REMOVE_ITEM_DONOT_EXISTS; } int ChewingLengthIndexLevel::add_index(int phrase_length, @@ -535,7 +535,7 @@ int ChewingLengthIndexLevel::remove_index(int phrase_length, assert(phrase_length + 1 < MAX_PHRASE_LENGTH); if (m_chewing_array_indexes->len <= phrase_length) - return REMOVE_ITEM_DONOT_EXISTS; + return ERROR_REMOVE_ITEM_DONOT_EXISTS; #define CASE(len) case len: \ { \ @@ -543,7 +543,7 @@ int ChewingLengthIndexLevel::remove_index(int phrase_length, (m_chewing_array_indexes, \ ChewingArrayIndexLevel *, len); \ if (NULL == array) \ - return REMOVE_ITEM_DONOT_EXISTS; \ + return ERROR_REMOVE_ITEM_DONOT_EXISTS; \ return array->remove_index(keys, token); \ } @@ -588,14 +588,14 @@ int ChewingArrayIndexLevel::add_index for (cur_elem = range.first; cur_elem != range.second; ++cur_elem) { if (cur_elem->m_token == token) - return INSERT_ITEM_EXISTS; + return ERROR_INSERT_ITEM_EXISTS; if (cur_elem->m_token > token) break; } int offset = (cur_elem - begin) * sizeof(IndexItem); m_chunk.insert_content(offset, &add_elem, sizeof(IndexItem)); - return INSERT_OK; + return ERROR_OK; } template @@ -619,11 +619,11 @@ int ChewingArrayIndexLevel::remove_index } if (cur_elem == range.second) - return REMOVE_ITEM_DONOT_EXISTS; + return ERROR_REMOVE_ITEM_DONOT_EXISTS; int offset = (cur_elem - begin) * sizeof(IndexItem); m_chunk.remove_content(offset, sizeof(IndexItem)); - return REMOVE_OK; + return ERROR_OK; } diff --git a/src/storage/phrase_large_table.cpp b/src/storage/phrase_large_table.cpp index 9e5e2d6..195024e 100644 --- a/src/storage/phrase_large_table.cpp +++ b/src/storage/phrase_large_table.cpp @@ -238,7 +238,7 @@ int PhraseBitmapIndexLevel::remove_index( int phrase_length, /* in */ ucs4_t phr PhraseLengthIndexLevel * &length_array = m_phrase_length_indexes[first_key]; if ( length_array ) return length_array->remove_index(phrase_length, phrase, token); - return REMOVE_ITEM_DONOT_EXISTS; + return ERROR_REMOVE_ITEM_DONOT_EXISTS; } int PhraseLengthIndexLevel::add_index( int phrase_length, /* in */ ucs4_t phrase[], /* in */ phrase_token_t token){ @@ -282,13 +282,13 @@ int PhraseLengthIndexLevel::add_index( int phrase_length, /* in */ ucs4_t phrase int PhraseLengthIndexLevel::remove_index( int phrase_length, /* in */ ucs4_t phrase[], /* out */ phrase_token_t & token){ assert(phrase_length + 1 < MAX_PHRASE_LENGTH); if ( m_phrase_array_indexes -> len <= phrase_length ) - return REMOVE_ITEM_DONOT_EXISTS; + return ERROR_REMOVE_ITEM_DONOT_EXISTS; #define CASE(len) case len: \ { \ PhraseArrayIndexLevel * &array = g_array_index \ (m_phrase_array_indexes, PhraseArrayIndexLevel *, len); \ if ( !array ) \ - return REMOVE_ITEM_DONOT_EXISTS; \ + return ERROR_REMOVE_ITEM_DONOT_EXISTS; \ return array->remove_index(phrase, token); \ } @@ -328,14 +328,14 @@ int PhraseArrayIndexLevel::add_index(/* in */ ucs4_t phrase[], /* assert(range.second - range.first <= 1); if ( range.second - range.first == 1 ) - return INSERT_ITEM_EXISTS; + return ERROR_INSERT_ITEM_EXISTS; PhraseIndexItem * cur_elem = range.first; int offset = (cur_elem - buf_begin) * sizeof(PhraseIndexItem); m_chunk.insert_content(offset, &new_elem, sizeof(PhraseIndexItem )); - return INSERT_OK; + return ERROR_OK; } template @@ -352,13 +352,13 @@ int PhraseArrayIndexLevel::remove_index(/* in */ ucs4_t phrase[], assert(range.second - range.first <= 1); PhraseIndexItem * cur_elem = range.first; if ( range.first == range.second || cur_elem == buf_end) - return REMOVE_ITEM_DONOT_EXISTS; + return ERROR_REMOVE_ITEM_DONOT_EXISTS; token = cur_elem->m_token; int offset = (cur_elem - buf_begin) * sizeof(PhraseIndexItem); m_chunk.remove_content(offset, sizeof (PhraseIndexItem)); - return REMOVE_OK; + return ERROR_OK; } bool PhraseLargeTable::load_text(FILE * infile){ -- cgit