summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-11-06 11:42:15 +0800
committerPeng Wu <alexepico@gmail.com>2012-11-06 11:42:15 +0800
commit49e3546a9fd5a655411af1840ed422bf0d67101d (patch)
tree888a5553e3e8423948ea49c4fabfbeee07204906 /src
parent92f204109d210d3670986fee625d9d708fb53a2d (diff)
downloadlibpinyin-49e3546a9fd5a655411af1840ed422bf0d67101d.tar.gz
libpinyin-49e3546a9fd5a655411af1840ed422bf0d67101d.tar.xz
libpinyin-49e3546a9fd5a655411af1840ed422bf0d67101d.zip
write remove index
Diffstat (limited to 'src')
-rw-r--r--src/storage/chewing_large_table.cpp15
-rw-r--r--src/storage/phrase_large_table2.cpp20
2 files changed, 29 insertions, 6 deletions
diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp
index 7779aae..7639dfe 100644
--- a/src/storage/chewing_large_table.cpp
+++ b/src/storage/chewing_large_table.cpp
@@ -560,8 +560,19 @@ int ChewingLengthIndexLevel::remove_index(int phrase_length,
(m_chewing_array_indexes, \
ChewingArrayIndexLevel<len> *, len); \
if (NULL == array) \
- return ERROR_REMOVE_ITEM_DONOT_EXISTS; \
- return array->remove_index(keys, token); \
+ return ERROR_REMOVE_ITEM_DONOT_EXISTS; \
+ int retval = array->remove_index(keys, token); \
+ \
+ /* remove empty array. */ \
+ if (0 == array->get_length()) { \
+ delete array; \
+ array = NULL; \
+ \
+ /* shrink self array. */ \
+ g_array_set_size(m_chewing_array_indexes, \
+ get_length()); \
+ } \
+ return retval; \
}
switch (phrase_length) {
diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp
index 7ed470f..f336e58 100644
--- a/src/storage/phrase_large_table2.cpp
+++ b/src/storage/phrase_large_table2.cpp
@@ -359,11 +359,23 @@ int PhraseLengthIndexLevel2::remove_index(int phrase_length,
#define CASE(len) case len: \
{ \
- PhraseArrayIndexLevel2<len> * & array = g_array_index \
- (m_phrase_array_indexes, PhraseArrayIndexLevel2<len> *, len - 1); \
- if ( !array ) \
+ PhraseArrayIndexLevel2<len> * & array = g_array_index \
+ (m_phrase_array_indexes, \
+ PhraseArrayIndexLevel2<len> *, len - 1); \
+ if (NULL == array) \
return ERROR_REMOVE_ITEM_DONOT_EXISTS; \
- return array->remove_index(phrase, token); \
+ int retval = array->remove_index(phrase, token); \
+ \
+ /* remove empty array. */ \
+ if (0 == array->get_length()) { \
+ delete array; \
+ array = NULL; \
+ \
+ /* shrink self array. */ \
+ g_array_set_size(m_phrase_array_indexes, \
+ get_length()); \
+ } \
+ return retval; \
}
switch(phrase_length){