diff options
author | Peng Wu <alexepico@gmail.com> | 2016-01-25 15:00:57 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-01-25 15:00:57 +0800 |
commit | fa4854d1ef818aec6457698f2cf503147c039dbd (patch) | |
tree | d6a8e05891b36ce3a8a983e68bc181d4f36a11d2 /src/storage/phrase_large_table3.cpp | |
parent | cbc65ce11de0b735aeba598357a5b25ad026de6e (diff) | |
download | libpinyin-fa4854d1ef818aec6457698f2cf503147c039dbd.tar.gz libpinyin-fa4854d1ef818aec6457698f2cf503147c039dbd.tar.xz libpinyin-fa4854d1ef818aec6457698f2cf503147c039dbd.zip |
write PhraseTableEntry::add_index method
Diffstat (limited to 'src/storage/phrase_large_table3.cpp')
-rw-r--r-- | src/storage/phrase_large_table3.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/storage/phrase_large_table3.cpp b/src/storage/phrase_large_table3.cpp index 2e1c188..27b8706 100644 --- a/src/storage/phrase_large_table3.cpp +++ b/src/storage/phrase_large_table3.cpp @@ -34,6 +34,8 @@ void PhraseTableEntry::set_header(table_entry_header_t header) { *head = header; } +/* search method */ + int PhraseTableEntry::search(/* out */ PhraseTokens tokens) const { int result = SEARCH_NONE; @@ -66,6 +68,39 @@ int PhraseTableEntry::search(/* out */ PhraseTokens tokens) const { return result; } +/* add_index/remove_index method */ +int PhraseTableEntry::add_index(/* in */ phrase_token_t token) { + const char * content = (char *) m_chunk.begin() + + sizeof(table_entry_header_t); + const phrase_token_t * begin = (phrase_token_t *) content; + const phrase_token_t * end = (phrase_token_t *) m_chunk.end(); + + const phrase_token_t * cur_token; + for (cur_token = begin; cur_token != end; ++cur_token) { + if (*cur_token == token) + return ERROR_INSERT_ITEM_EXISTS; + if (*cur_token > token) + break; + } + + int offset = sizeof(table_entry_header_t) /* header */ + + (cur_token - begin) * sizeof(phrase_token_t); + m_chunk.insert_content(offset, &token, sizeof(phrase_token_t)); + return ERROR_OK; +} + + + +/* get length method */ +int PhraseTableEntry::get_length() const { + const char * content = (char *) m_chunk.begin() + + sizeof(table_entry_header_t); + const phrase_token_t * begin = (phrase_token_t *) content; + const phrase_token_t * end = (phrase_token_t *) m_chunk.end(); + + return begin - end; +} + /* load text method */ |