add ErrorResult
authorPeng Wu <alexepico@gmail.com>
Thu, 21 Jun 2012 05:06:33 +0000 (13:06 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 21 Jun 2012 05:06:33 +0000 (13:06 +0800)
src/include/novel_types.h
src/storage/chewing_large_table.cpp
src/storage/phrase_large_table.cpp

index de249ca..014c11a 100644 (file)
@@ -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;
index cfcb987..9185976 100644 (file)
@@ -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;
 }
 
 
index 9e5e2d6..195024e 100644 (file)
@@ -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){