diff options
author | Peng Wu <alexepico@gmail.com> | 2016-01-07 14:48:05 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-01-07 14:48:05 +0800 |
commit | 2185ba0adf256e4fac611a5fafbff23ded0ef314 (patch) | |
tree | b5835ae2737fb83d06c456c34d206e26979e5b79 /src/storage/phrase_large_table3.h | |
parent | 719018effb4077de11c09e451278a7c7866e1669 (diff) | |
download | libpinyin-2185ba0adf256e4fac611a5fafbff23ded0ef314.tar.gz libpinyin-2185ba0adf256e4fac611a5fafbff23ded0ef314.tar.xz libpinyin-2185ba0adf256e4fac611a5fafbff23ded0ef314.zip |
refactor code
Diffstat (limited to 'src/storage/phrase_large_table3.h')
-rw-r--r-- | src/storage/phrase_large_table3.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/storage/phrase_large_table3.h b/src/storage/phrase_large_table3.h index 51cbf20..1bd450d 100644 --- a/src/storage/phrase_large_table3.h +++ b/src/storage/phrase_large_table3.h @@ -75,6 +75,42 @@ public: bool mask_out(phrase_token_t mask, phrase_token_t value); }; +static inline int reduce_tokens(const PhraseTokens tokens, + TokenVector tokenarray) { + int num = 0; + g_array_set_size(tokenarray, 0); + + for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { + GArray * array = tokens[i]; + if (NULL == array) + continue; + + num += array->len; + + g_array_append_vals(tokenarray, array->data, array->len); + } + + /* the following line will be removed in future after code are verified. */ + assert(0 <= num && num <= 4); + + return num; +} + +/* for compatibility. */ +static inline int get_first_token(const PhraseTokens tokens, + /* out */ phrase_token_t & token){ + token = null_token; + + TokenVector tokenarray = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); + int num = reduce_tokens(tokens, tokenarray); + if (num) + token = g_array_index(tokenarray, phrase_token_t, 0); + g_array_free(tokenarray, TRUE); + + return num; +} + + }; #endif |