diff options
author | 2012-01-30 01:04:42 -0800 | |
---|---|---|
committer | 2012-01-30 01:04:42 -0800 | |
commit | a191afb78d47022a1cc4474ffa7d7ab872a9270b (patch) | |
tree | 69a46408b2842f09afe69e99197cd408b1bab960 /native/src/words_priority_queue_pool.h | |
parent | 3b0f2bf169c23ea94c5a0adb275ce41b5c34ea83 (diff) | |
parent | 1f6b52e76c59700984fe2b7d7b436d81da997e93 (diff) | |
download | latinime-a191afb78d47022a1cc4474ffa7d7ab872a9270b.tar.gz latinime-a191afb78d47022a1cc4474ffa7d7ab872a9270b.tar.xz latinime-a191afb78d47022a1cc4474ffa7d7ab872a9270b.zip |
Merge "Implement multi words suggestions step1"
Diffstat (limited to 'native/src/words_priority_queue_pool.h')
-rw-r--r-- | native/src/words_priority_queue_pool.h | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/native/src/words_priority_queue_pool.h b/native/src/words_priority_queue_pool.h index a4aa8b6ca..5b50e8f4f 100644 --- a/native/src/words_priority_queue_pool.h +++ b/native/src/words_priority_queue_pool.h @@ -27,11 +27,10 @@ class WordsPriorityQueuePool { public: WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) { mMasterQueue = new(mMasterQueueBuf) WordsPriorityQueue(mainQueueMaxWords, maxWordLength); - for (int i = 0, subQueueBufOffset = 0; i < SUB_QUEUE_MAX_COUNT; + for (int i = 0, subQueueBufOffset = 0; + i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; ++i, subQueueBufOffset += sizeof(WordsPriorityQueue)) { - mSubQueues1[i] = new(mSubQueueBuf1 + subQueueBufOffset) - WordsPriorityQueue(subQueueMaxWords, maxWordLength); - mSubQueues2[i] = new(mSubQueueBuf2 + subQueueBufOffset) + mSubQueues[i] = new(mSubQueueBuf + subQueueBufOffset) WordsPriorityQueue(subQueueMaxWords, maxWordLength); } } @@ -44,7 +43,7 @@ class WordsPriorityQueuePool { } WordsPriorityQueue* getSubQueue(const int wordIndex, const int inputWordLength) { - if (wordIndex > SUB_QUEUE_MAX_WORD_INDEX) { + if (wordIndex >= MULTIPLE_WORDS_SUGGESTION_MAX_WORDS) { return 0; } if (inputWordLength < 0 || inputWordLength >= SUB_QUEUE_MAX_COUNT) { @@ -53,30 +52,21 @@ class WordsPriorityQueuePool { } return 0; } - // TODO: Come up with more generic pool - if (wordIndex == 1) { - return mSubQueues1[inputWordLength]; - } else if (wordIndex == 2) { - return mSubQueues2[inputWordLength]; - } else { - return 0; - } + return mSubQueues[wordIndex * SUB_QUEUE_MAX_COUNT + inputWordLength]; } inline void clearAll() { mMasterQueue->clear(); - for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { - mSubQueues1[i]->clear(); - mSubQueues2[i]->clear(); + for (int i = 0; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS; ++i) { + clearSubQueue(i); } } inline void clearSubQueue(const int wordIndex) { for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { - if (wordIndex == 1) { - mSubQueues1[i]->clear(); - } else if (wordIndex == 2) { - mSubQueues2[i]->clear(); + WordsPriorityQueue* queue = getSubQueue(wordIndex, i); + if (queue) { + queue->clear(); } } } @@ -84,17 +74,16 @@ class WordsPriorityQueuePool { void dumpSubQueue1TopSuggestions() { AKLOGI("DUMP SUBQUEUE1 TOP SUGGESTIONS"); for (int i = 0; i < SUB_QUEUE_MAX_COUNT; ++i) { - mSubQueues1[i]->dumpTopWord(); + getSubQueue(0, i)->dumpTopWord(); } } private: WordsPriorityQueue* mMasterQueue; - WordsPriorityQueue* mSubQueues1[SUB_QUEUE_MAX_COUNT]; - WordsPriorityQueue* mSubQueues2[SUB_QUEUE_MAX_COUNT]; + WordsPriorityQueue* mSubQueues[SUB_QUEUE_MAX_COUNT * MULTIPLE_WORDS_SUGGESTION_MAX_WORDS]; char mMasterQueueBuf[sizeof(WordsPriorityQueue)]; - char mSubQueueBuf1[SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; - char mSubQueueBuf2[SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; + char mSubQueueBuf[MULTIPLE_WORDS_SUGGESTION_MAX_WORDS + * SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; }; } |