diff options
Diffstat (limited to 'native/src/words_priority_queue.h')
-rw-r--r-- | native/src/words_priority_queue.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/native/src/words_priority_queue.h b/native/src/words_priority_queue.h index 6262439b5..c85f2b9b3 100644 --- a/native/src/words_priority_queue.h +++ b/native/src/words_priority_queue.h @@ -47,6 +47,7 @@ class WordsPriorityQueue { for (int i = 0; i < maxWordLength; ++i) { mSuggestedWords[i].mUsed = false; } + mHighestSuggestedWord = 0; } ~WordsPriorityQueue() { @@ -79,6 +80,9 @@ class WordsPriorityQueue { DUMP_WORD(word, wordLength); } mSuggestions.push(sw); + if (!mHighestSuggestedWord || mHighestSuggestedWord->mScore < sw->mScore) { + mHighestSuggestedWord = sw; + } } SuggestedWord* top() { @@ -88,6 +92,7 @@ class WordsPriorityQueue { } int outputSuggestions(int *frequencies, unsigned short *outputChars) { + mHighestSuggestedWord = 0; const unsigned int size = min(MAX_WORDS, mSuggestions.size()); int index = size - 1; while (!mSuggestions.empty() && index >= 0) { @@ -116,6 +121,7 @@ class WordsPriorityQueue { } void clear() { + mHighestSuggestedWord = 0; while (!mSuggestions.empty()) { SuggestedWord* sw = mSuggestions.top(); if (DEBUG_WORDS_PRIORITY_QUEUE) { @@ -134,6 +140,28 @@ class WordsPriorityQueue { DUMP_WORD(mSuggestions.top()->mWord, mSuggestions.top()->mWordLength); } + double getHighestNormalizedScore(const unsigned short* before, const int beforeLength, + unsigned short** outWord, int *outScore, int *outLength) { + if (!mHighestSuggestedWord) { + return 0.0; + } + SuggestedWord* sw = mHighestSuggestedWord; + const int score = sw->mScore; + unsigned short* word = sw->mWord; + const int wordLength = sw->mWordLength; + if (outScore) { + *outScore = score; + } + if (outWord) { + *outWord = word; + } + if (outLength) { + *outLength = wordLength; + } + return Correction::RankingAlgorithm::calcNormalizedScore( + before, beforeLength, word, wordLength, score); + } + private: struct wordComparator { bool operator ()(SuggestedWord * left, SuggestedWord * right) { @@ -158,6 +186,7 @@ class WordsPriorityQueue { const unsigned int MAX_WORDS; const unsigned int MAX_WORD_LENGTH; SuggestedWord* mSuggestedWords; + SuggestedWord* mHighestSuggestedWord; }; } |