From 4f3e1e5075b998b08dcec7d11d85ffb098ca9dcb Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Sat, 1 Sep 2012 11:50:31 +0800 Subject: write prepare/destroy tokens --- src/storage/phrase_index.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/storage/phrase_index.h') diff --git a/src/storage/phrase_index.h b/src/storage/phrase_index.h index d59865d..64fcec5 100644 --- a/src/storage/phrase_index.h +++ b/src/storage/phrase_index.h @@ -690,6 +690,47 @@ public: return true; } + /** + * FacadePhraseIndex::prepare_tokens: + * @tokens: the tokens to be prepared. + * @returns: whether the prepare operation is successful. + * + * Prepare the tokens. + * + */ + bool prepare_tokens(PhraseTokens tokens) { + /* assume memset(tokens, 0, sizeof(tokens)); */ + for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { + GArray * & token = tokens[i]; + assert(NULL == token); + + SubPhraseIndex * sub_phrase = m_sub_phrase_indices[i]; + if (sub_phrase) { + token = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); + } + } + return true; + } + + /** + * FacadePhraseIndex::destroy_tokens: + * @tokens: the tokens to be destroyed. + * @returns: whether the destroy operation is successful. + * + * Destroy the tokens. + * + */ + bool destroy_tokens(PhraseTokens tokens) { + for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { + GArray * & token = tokens[i]; + if (token) { + g_array_free(token, TRUE); + token = NULL; + } + } + return true; + } + /** * FacadePhraseIndex::create_sub_phrase: * @index: the phrase index to be created. -- cgit