aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/words_priority_queue.cpp
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2012-11-06 12:49:53 +0900
committerSatoshi Kataoka <satok@google.com>2012-11-06 12:49:53 +0900
commit555e15a96a00e8829981557d96e9fa7fc5a74f8c (patch)
tree9750c7af9777b63c176cc780c2a6de4849931434 /native/jni/src/words_priority_queue.cpp
parent9381ab669f12664f7e2debea846d3ce71f89b256 (diff)
parent5f2fa6b82cbb6714ab2996aebc16f10c62d0e673 (diff)
downloadlatinime-555e15a96a00e8829981557d96e9fa7fc5a74f8c.tar.gz
latinime-555e15a96a00e8829981557d96e9fa7fc5a74f8c.tar.xz
latinime-555e15a96a00e8829981557d96e9fa7fc5a74f8c.zip
Merge remote-tracking branch 'goog/master' into mergescriptpackage
Conflicts: java/res/values-ca/strings.xml java/res/values-cs/strings.xml java/res/values-de/strings.xml java/res/values-es/strings.xml java/res/values-hr/strings.xml java/res/values-hu/strings.xml java/res/values-it/strings.xml java/res/values-lv/strings.xml java/res/values-nb/strings.xml java/res/values-nl/strings.xml java/res/values-pl/strings.xml java/res/values-pt/strings.xml java/res/values-ro/strings.xml java/res/values-ru/strings.xml java/res/values-sv/strings.xml java/res/values-sw/strings.xml java/res/values-tr/strings.xml java/res/values-uk/strings.xml java/res/values-zh-rCN/strings.xml java/res/values-zh-rTW/strings.xml java/src/com/android/inputmethod/latin/RichInputConnection.java Change-Id: Iba00dd5b86cb16d72968bc7e40d75853845b6dcb
Diffstat (limited to 'native/jni/src/words_priority_queue.cpp')
-rw-r--r--native/jni/src/words_priority_queue.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/native/jni/src/words_priority_queue.cpp b/native/jni/src/words_priority_queue.cpp
new file mode 100644
index 000000000..7e18d0f87
--- /dev/null
+++ b/native/jni/src/words_priority_queue.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "words_priority_queue.h"
+
+namespace latinime {
+
+int WordsPriorityQueue::outputSuggestions(const int *before, const int beforeLength,
+ int *frequencies, int *outputCodePoints, int* outputTypes) {
+ mHighestSuggestedWord = 0;
+ const int size = min(MAX_WORDS, static_cast<int>(mSuggestions.size()));
+ SuggestedWord *swBuffer[size];
+ int index = size - 1;
+ while (!mSuggestions.empty() && index >= 0) {
+ SuggestedWord *sw = mSuggestions.top();
+ if (DEBUG_WORDS_PRIORITY_QUEUE) {
+ AKLOGI("dump word. %d", sw->mScore);
+ DUMP_WORD(sw->mWord, sw->mWordLength);
+ }
+ swBuffer[index] = sw;
+ mSuggestions.pop();
+ --index;
+ }
+ if (size >= 2) {
+ SuggestedWord *nsMaxSw = 0;
+ int maxIndex = 0;
+ float maxNs = 0;
+ for (int i = 0; i < size; ++i) {
+ SuggestedWord *tempSw = swBuffer[i];
+ if (!tempSw) {
+ continue;
+ }
+ const float tempNs = getNormalizedScore(tempSw, before, beforeLength, 0, 0, 0);
+ if (tempNs >= maxNs) {
+ maxNs = tempNs;
+ maxIndex = i;
+ nsMaxSw = tempSw;
+ }
+ }
+ if (maxIndex > 0 && nsMaxSw) {
+ memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(swBuffer[0]));
+ swBuffer[0] = nsMaxSw;
+ }
+ }
+ for (int i = 0; i < size; ++i) {
+ SuggestedWord *sw = swBuffer[i];
+ if (!sw) {
+ AKLOGE("SuggestedWord is null %d", i);
+ continue;
+ }
+ const int wordLength = sw->mWordLength;
+ int *targetAddress = outputCodePoints + i * MAX_WORD_LENGTH;
+ frequencies[i] = sw->mScore;
+ outputTypes[i] = sw->mType;
+ memcpy(targetAddress, sw->mWord, wordLength * sizeof(targetAddress[0]));
+ if (wordLength < MAX_WORD_LENGTH) {
+ targetAddress[wordLength] = 0;
+ }
+ sw->mUsed = false;
+ }
+ return size;
+}
+} // namespace latinime