summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-06-21 13:06:33 +0800
committerPeng Wu <alexepico@gmail.com>2012-06-21 13:06:33 +0800
commit606b4b110302fad6590eca56cba7108681b8b434 (patch)
treef062b173011b21143538d7f12bc8f5710f695d97
parent9aa87d6bdadf9492a3c09d49841e23052c043d16 (diff)
downloadlibpinyin-606b4b110302fad6590eca56cba7108681b8b434.tar.gz
libpinyin-606b4b110302fad6590eca56cba7108681b8b434.tar.xz
libpinyin-606b4b110302fad6590eca56cba7108681b8b434.zip
add ErrorResult
-rw-r--r--src/include/novel_types.h25
-rw-r--r--src/storage/chewing_large_table.cpp14
-rw-r--r--src/storage/phrase_large_table.cpp14
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> *, 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<phrase_length>::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<int phrase_length>
@@ -619,11 +619,11 @@ int ChewingArrayIndexLevel<phrase_length>::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<len> * &array = g_array_index \
(m_phrase_array_indexes, PhraseArrayIndexLevel<len> *, 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<phrase_length>::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<phrase_length> * cur_elem = range.first;
int offset = (cur_elem - buf_begin) *
sizeof(PhraseIndexItem<phrase_length>);
m_chunk.insert_content(offset, &new_elem,
sizeof(PhraseIndexItem<phrase_length> ));
- return INSERT_OK;
+ return ERROR_OK;
}
template<size_t phrase_length>
@@ -352,13 +352,13 @@ int PhraseArrayIndexLevel<phrase_length>::remove_index(/* in */ ucs4_t phrase[],
assert(range.second - range.first <= 1);
PhraseIndexItem<phrase_length> * 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<phrase_length>);
m_chunk.remove_content(offset, sizeof (PhraseIndexItem<phrase_length>));
- return REMOVE_OK;
+ return ERROR_OK;
}
bool PhraseLargeTable::load_text(FILE * infile){