summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-11-05 13:41:01 +0800
committerPeng Wu <alexepico@gmail.com>2012-11-05 13:41:01 +0800
commit52d001b0833ad3578873751bcb80010853add60f (patch)
tree4faf1b9fd2242fcbd73dafcd26dcdb8d6173bf94 /src
parent96bddf9da58eb418dfea8ed9aff539f33c558b69 (diff)
downloadlibpinyin-52d001b0833ad3578873751bcb80010853add60f.tar.gz
libpinyin-52d001b0833ad3578873751bcb80010853add60f.tar.xz
libpinyin-52d001b0833ad3578873751bcb80010853add60f.zip
write get length in progress
Diffstat (limited to 'src')
-rw-r--r--src/storage/phrase_large_table2.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/storage/phrase_large_table2.cpp b/src/storage/phrase_large_table2.cpp
index 94edfe0..7d3d83b 100644
--- a/src/storage/phrase_large_table2.cpp
+++ b/src/storage/phrase_large_table2.cpp
@@ -48,6 +48,9 @@ public:
/* in */ phrase_token_t token);
int remove_index(int phrase_length, /* in */ ucs4_t phrase[],
/* in */ phrase_token_t token);
+
+ /* get length method */
+ int get_length() const;
};
@@ -80,6 +83,9 @@ public:
/* add_index/remove_index method */
int add_index(/* in */ ucs4_t phrase[], /* in */ phrase_token_t token);
int remove_index(/* in */ ucs4_t phrase[], /* in */ phrase_token_t token);
+
+ /* get length method */
+ int get_length() const;
};
};
@@ -652,3 +658,32 @@ store(MemoryChunk * new_chunk, table_offset_t offset, table_offset_t & end) {
end = offset + m_chunk.size();
return true;
}
+
+
+/* get length method */
+
+int PhraseLengthIndexLevel2::get_length() const {
+ int length = m_phrase_array_indexes->len;
+
+ /* trim trailing zero. */
+ for (int i = length - 1; i >= 0; --i) {
+ void * array = g_array_index(m_phrase_array_indexes, void *, i);
+
+ if (NULL != array)
+ break;
+
+ --length;
+ }
+
+ return length;
+}
+
+
+template<size_t phrase_length>
+int PhraseArrayIndexLevel2<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;
+}