re-factor remove index in progress
authorPeng Wu <alexepico@gmail.com>
Tue, 6 Nov 2012 03:12:19 +0000 (11:12 +0800)
committerPeng Wu <alexepico@gmail.com>
Tue, 6 Nov 2012 03:20:32 +0000 (11:20 +0800)
src/storage/chewing_large_table.cpp
src/storage/phrase_large_table2.cpp

index 68eb3ed..7779aae 100644 (file)
@@ -488,9 +488,18 @@ int ChewingBitmapIndexLevel::remove_index(int phrase_length,
         [first_key.m_initial][first_key.m_middle]
         [first_key.m_final][first_key.m_tone];
 
-    if (length_array)
-        return length_array->remove_index(phrase_length - 1, keys + 1, token);
-    return ERROR_REMOVE_ITEM_DONOT_EXISTS;
+    if (NULL == length_array)
+        return ERROR_REMOVE_ITEM_DONOT_EXISTS;
+
+    int retval = length_array->remove_index(phrase_length - 1, keys + 1, token);
+
+    /* remove empty array. */
+    if (0 == length_array->get_length()) {
+        delete length_array;
+        length_array = NULL;
+    }
+
+    return retval;
 }
 
 int ChewingLengthIndexLevel::add_index(int phrase_length,
index 7a045e4..7ed470f 100644 (file)
@@ -292,10 +292,18 @@ int PhraseBitmapIndexLevel2::remove_index(int phrase_length,
     PhraseLengthIndexLevel2 * & length_array =
         m_phrase_length_indexes[first_key];
 
-    if ( length_array )
-        return length_array->remove_index(phrase_length, phrase, token);
+    if (NULL == length_array)
+        return ERROR_REMOVE_ITEM_DONOT_EXISTS;
+
+    int retval = length_array->remove_index(phrase_length, phrase, token);
+
+    /* remove empty array. */
+    if (0 == length_array->get_length()) {
+        delete length_array;
+        length_array = NULL;
+    }
 
-    return ERROR_REMOVE_ITEM_DONOT_EXISTS;
+    return retval;
 }
 
 int PhraseLengthIndexLevel2::add_index(int phrase_length,