diff options
author | Peng Wu <alexepico@gmail.com> | 2012-11-05 13:55:34 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-11-05 13:56:49 +0800 |
commit | ed47add4965f5a22f697e1ec795be9e03065b18a (patch) | |
tree | b0b2e7abc5701b6a638170ecfe58773022622613 /src/storage | |
parent | 52d001b0833ad3578873751bcb80010853add60f (diff) | |
download | libpinyin-ed47add4965f5a22f697e1ec795be9e03065b18a.tar.gz libpinyin-ed47add4965f5a22f697e1ec795be9e03065b18a.tar.xz libpinyin-ed47add4965f5a22f697e1ec795be9e03065b18a.zip |
write get length
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/chewing_large_table.cpp | 34 | ||||
-rw-r--r-- | src/storage/phrase_large_table2.cpp | 1 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index 8eb43d3..68eb3ed 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -53,6 +53,9 @@ public: /* in */ phrase_token_t token); int remove_index(int phrase_length, /* in */ ChewingKey keys[], /* in */ phrase_token_t token); + + /* get length method */ + int get_length() const; }; @@ -85,6 +88,9 @@ public: int add_index(/* in */ ChewingKey keys[], /* in */ phrase_token_t token); int remove_index(/* in */ ChewingKey keys[], /* in */ phrase_token_t token); + + /* get length method */ + int get_length() const; }; }; @@ -890,3 +896,31 @@ store(MemoryChunk * new_chunk, table_offset_t offset, table_offset_t & end) { end = offset + m_chunk.size(); return true; } + + +/* get length method */ + +int ChewingLengthIndexLevel::get_length() const { + int length = m_chewing_array_indexes->len; + + /* trim trailing zero. */ + for (int i = length - 1; i >= 0; --i) { + void * array = g_array_index(m_chewing_array_indexes, void *, i); + + if (NULL != array) + break; + + --length; + } + + return length; +} + +template<size_t phrase_length> +int ChewingArrayIndexLevel<phrase_length>::get_length() const { + IndexItem * chunk_begin = NULL, * chunk_end = NULL; + chunk_begin = (IndexItem *) m_chunk.begin(); + chunk_end = (IndexItem *) m_chunk.end(); + + return chunk_end - chunk_begin; +} diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp index 7d3d83b..7a045e4 100644 --- a/src/storage/phrase_large_table2.cpp +++ b/src/storage/phrase_large_table2.cpp @@ -678,7 +678,6 @@ int PhraseLengthIndexLevel2::get_length() const { return length; } - template<size_t phrase_length> int PhraseArrayIndexLevel2<phrase_length>::get_length() const { IndexItem * chunk_begin = NULL, * chunk_end = NULL; |