aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/src')
-rw-r--r--native/jni/src/binary_format.h16
-rw-r--r--native/jni/src/correction.cpp8
-rw-r--r--native/jni/src/correction.h19
-rw-r--r--native/jni/src/defines.h29
-rw-r--r--native/jni/src/dic_traverse_wrapper.h8
-rw-r--r--native/jni/src/proximity_info.cpp4
-rw-r--r--native/jni/src/proximity_info.h67
-rw-r--r--native/jni/src/proximity_info_params.cpp14
-rw-r--r--native/jni/src/proximity_info_params.h20
-rw-r--r--native/jni/src/proximity_info_state.cpp5
-rw-r--r--native/jni/src/proximity_info_state.h2
-rw-r--r--native/jni/src/proximity_info_state_utils.cpp79
-rw-r--r--native/jni/src/proximity_info_utils.h39
-rw-r--r--native/jni/src/words_priority_queue.h7
14 files changed, 129 insertions, 188 deletions
diff --git a/native/jni/src/binary_format.h b/native/jni/src/binary_format.h
index 61780dea5..2d7c4b492 100644
--- a/native/jni/src/binary_format.h
+++ b/native/jni/src/binary_format.h
@@ -18,9 +18,9 @@
#define LATINIME_BINARY_FORMAT_H
#include <cstdlib>
-#include <limits>
#include <map>
#include <stdint.h>
+
#include "bloom_filter.h"
#include "char_utils.h"
@@ -66,8 +66,8 @@ class BinaryFormat {
static int detectFormat(const uint8_t *const dict);
static int getHeaderSize(const uint8_t *const dict);
static int getFlags(const uint8_t *const dict);
- static void readHeaderValue(const uint8_t *const dict, const char *const key,
- int *outValue, const int outValueSize);
+ static void readHeaderValue(const uint8_t *const dict, const char *const key, int *outValue,
+ const int outValueSize);
static int readHeaderValueInt(const uint8_t *const dict, const char *const key);
static int getGroupCountAndForwardPointer(const uint8_t *const dict, int *pos);
static uint8_t getFlagsAndForwardPointer(const uint8_t *const dict, int *pos);
@@ -168,7 +168,7 @@ inline int BinaryFormat::getHeaderSize(const uint8_t *const dict) {
// See the format of the header in the comment in detectFormat() above
return (dict[8] << 24) + (dict[9] << 16) + (dict[10] << 8) + dict[11];
default:
- return std::numeric_limits<int>::max();
+ return S_INT_MAX;
}
}
@@ -197,8 +197,7 @@ inline void BinaryFormat::readHeaderValue(const uint8_t *const dict, const char
if (codePoint == NOT_A_CODE_POINT && key[keyIndex] == 0) {
// We found the key! Copy and return the value.
codePoint = getCodePointAndForwardPointer(dict, &index);
- while (codePoint != NOT_A_CODE_POINT
- && outValueIndex < outValueSize) {
+ while (codePoint != NOT_A_CODE_POINT && outValueIndex < outValueSize) {
outValue[outValueIndex++] = codePoint;
codePoint = getCodePointAndForwardPointer(dict, &index);
}
@@ -314,7 +313,7 @@ static inline int childrenAddressSize(const uint8_t flags) {
}
static AK_FORCE_INLINE int shortcutByteSize(const uint8_t *const dict, const int pos) {
- return ((int)(dict[pos] << 8)) + (dict[pos + 1]);
+ return (static_cast<int>(dict[pos] << 8)) + (dict[pos + 1]);
}
inline int BinaryFormat::skipChildrenPosition(const uint8_t flags, const int pos) {
@@ -664,9 +663,8 @@ inline int BinaryFormat::getProbability(const int position, const std::map<int,
if (bigramFreqIt != bigramMap->end()) {
const int bigramFreq = bigramFreqIt->second;
return computeFrequencyForBigram(unigramFreq, bigramFreq);
- } else {
- return backoff(unigramFreq);
}
+ return backoff(unigramFreq);
}
} // namespace latinime
#endif // LATINIME_BINARY_FORMAT_H
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index e892c8591..d4bd4aa00 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -112,7 +112,7 @@ void Correction::setCorrectionParams(const int skipPos, const int excessivePos,
mMaxErrors = maxErrors;
}
-void Correction::checkState() {
+void Correction::checkState() const {
if (DEBUG_DICT) {
int inputCount = 0;
if (mSkipPos >= 0) ++inputCount;
@@ -121,12 +121,12 @@ void Correction::checkState() {
}
}
-bool Correction::sameAsTyped() {
+bool Correction::sameAsTyped() const {
return mProximityInfoState.sameAsTyped(mWord, mOutputIndex);
}
int Correction::getFreqForSplitMultipleWords(const int *freqArray, const int *wordLengthArray,
- const int wordCount, const bool isSpaceProximity, const int *word) {
+ const int wordCount, const bool isSpaceProximity, const int *word) const {
return Correction::RankingAlgorithm::calcFreqForSplitMultipleWords(freqArray, wordLengthArray,
wordCount, this, isSpaceProximity, word);
}
@@ -677,7 +677,7 @@ inline static bool isUpperCase(unsigned short c) {
const float factor =
SuggestUtils::getDistanceScalingFactor(static_cast<float>(squaredDistance));
if (factor > 0.0f) {
- multiplyRate((int)(factor * 100.0f), &finalFreq);
+ multiplyRate(static_cast<int>(factor * 100.0f), &finalFreq);
} else if (squaredDistance == PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO) {
multiplyRate(WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE, &finalFreq);
}
diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h
index 89e300d75..34f794d84 100644
--- a/native/jni/src/correction.h
+++ b/native/jni/src/correction.h
@@ -64,8 +64,8 @@ class Correction {
void setCorrectionParams(const int skipPos, const int excessivePos, const int transposedPos,
const int spaceProximityPos, const int missingSpacePos, const bool useFullEditDistance,
const bool doAutoCompletion, const int maxErrors);
- void checkState();
- bool sameAsTyped();
+ void checkState() const;
+ bool sameAsTyped() const;
bool initProcessState(const int index);
int getInputIndex() const;
@@ -77,7 +77,7 @@ class Correction {
}
int getFreqForSplitMultipleWords(const int *freqArray, const int *wordLengthArray,
- const int wordCount, const bool isSpaceProximity, const int *word);
+ const int wordCount, const bool isSpaceProximity, const int *word) const;
int getFinalProbability(const int probability, int **word, int *wordLength);
int getFinalProbabilityForSubQueue(const int probability, int **word, int *wordLength,
const int inputSize);
@@ -170,11 +170,10 @@ class Correction {
if (n <= 0) return 1;
if (base == 2) {
return n < 31 ? 1 << n : S_INT_MAX;
- } else {
- int ret = base;
- for (int i = 1; i < n; ++i) multiplyIntCapped(base, &ret);
- return ret;
}
+ int ret = base;
+ for (int i = 1; i < n; ++i) multiplyIntCapped(base, &ret);
+ return ret;
}
AK_FORCE_INLINE static void multiplyRate(const int rate, int *freq) {
@@ -318,13 +317,11 @@ AK_FORCE_INLINE Correction::CorrectionType Correction::processSkipChar(const int
addCharToCurrentWord(c);
mTerminalInputIndex = mInputIndex - (inputIndexIncremented ? 1 : 0);
mTerminalOutputIndex = mOutputIndex;
+ incrementOutputIndex();
if (mNeedsToTraverseAllNodes && isTerminal) {
- incrementOutputIndex();
return TRAVERSE_ALL_ON_TERMINAL;
- } else {
- incrementOutputIndex();
- return TRAVERSE_ALL_NOT_ON_TERMINAL;
}
+ return TRAVERSE_ALL_NOT_ON_TERMINAL;
}
inline Correction::CorrectionType Correction::processUnrelatedCorrectionType() {
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 922a746b8..a1fdae7a4 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -267,21 +267,6 @@ static inline void prof_out(void) {
// loading time, and acceptable even for several initial lookups which involve page faults.
#define USE_MMAP_FOR_DICTIONARY
-// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
-#define ADDRESS_MASK 0x3FFFFF
-
-// The bit that decides if an address follows in the next 22 bits
-#define FLAG_ADDRESS_MASK 0x40
-// The bit that decides if this is a terminal node for a word. The node could still have children,
-// if the word has other endings.
-#define FLAG_TERMINAL_MASK 0x80
-
-#define FLAG_BIGRAM_READ 0x80
-#define FLAG_BIGRAM_CHILDEXIST 0x40
-#define FLAG_BIGRAM_CONTINUED 0x80
-#define FLAG_BIGRAM_FREQ 0x7F
-
-#define DICTIONARY_VERSION_MIN 200
#define NOT_VALID_WORD (-99)
#define NOT_A_CODE_POINT (-1)
#define NOT_A_DISTANCE (-1)
@@ -297,10 +282,6 @@ static inline void prof_out(void) {
#define KEYCODE_HYPHEN_MINUS '-'
#define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true
-
-#define SUGGEST_WORDS_WITH_MISSING_CHARACTER true
-#define SUGGEST_WORDS_WITH_EXCESSIVE_CHARACTER true
-#define SUGGEST_WORDS_WITH_TRANSPOSED_CHARACTERS true
#define SUGGEST_MULTIPLE_WORDS true
// The following "rate"s are used as a multiplier before dividing by 100, so they are in percent.
@@ -366,11 +347,10 @@ static inline void prof_out(void) {
#define DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH 5
#define MIN_USER_TYPED_LENGTH_FOR_MULTIPLE_WORD_SUGGESTION 3
-#define MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION 3
// TODO: Remove
#define MAX_POINTER_COUNT 1
-#define MAX_POINTER_COUNT_FOR_G 2
+#define MAX_POINTER_COUNT_G 2
// Size, in bytes, of the bloom filter index for bigrams
// 128 gives us 1024 buckets. The probability of false positive is (1 - e ** (-kn/m))**k,
@@ -390,14 +370,11 @@ static inline void prof_out(void) {
#error "BIGRAM_FILTER_MODULO is larger than BIGRAM_FILTER_BYTE_SIZE"
#endif
-template<typename T> inline T min(T a, T b) { return a < b ? a : b; }
-template<typename T> inline T max(T a, T b) { return a > b ? a : b; }
+template<typename T> AK_FORCE_INLINE const T &min(const T &a, const T &b) { return a < b ? a : b; }
+template<typename T> AK_FORCE_INLINE const T &max(const T &a, const T &b) { return a > b ? a : b; }
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
-// The ratio of neutral area radius to sweet spot radius.
-#define NEUTRAL_AREA_RADIUS_RATIO 1.3f
-
// DEBUG
#define INPUTLENGTH_FOR_DEBUG (-1)
#define MIN_OUTPUT_INDEX_FOR_DEBUG (-1)
diff --git a/native/jni/src/dic_traverse_wrapper.h b/native/jni/src/dic_traverse_wrapper.h
index 9a1db3852..1108a45c8 100644
--- a/native/jni/src/dic_traverse_wrapper.h
+++ b/native/jni/src/dic_traverse_wrapper.h
@@ -31,8 +31,8 @@ class DicTraverseWrapper {
}
return 0;
}
- static void initDicTraverseSession(void *traverseSession,
- const Dictionary *const dictionary, const int *prevWord, const int prevWordLength) {
+ static void initDicTraverseSession(void *traverseSession, const Dictionary *const dictionary,
+ const int *prevWord, const int prevWordLength) {
if (sDicTraverseSessionInitMethod) {
sDicTraverseSessionInitMethod(traverseSession, dictionary, prevWord, prevWordLength);
}
@@ -42,8 +42,7 @@ class DicTraverseWrapper {
sDicTraverseSessionReleaseMethod(traverseSession);
}
}
- static void setTraverseSessionFactoryMethod(
- void *(*factoryMethod)(JNIEnv *, jstring)) {
+ static void setTraverseSessionFactoryMethod(void *(*factoryMethod)(JNIEnv *, jstring)) {
sDicTraverseSessionFactoryMethod = factoryMethod;
}
static void setTraverseSessionInitMethod(
@@ -53,6 +52,7 @@ class DicTraverseWrapper {
static void setTraverseSessionReleaseMethod(void (*releaseMethod)(void *)) {
sDicTraverseSessionReleaseMethod = releaseMethod;
}
+
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
static void *(*sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring);
diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp
index 8157fe2d0..a0bad1af4 100644
--- a/native/jni/src/proximity_info.cpp
+++ b/native/jni/src/proximity_info.cpp
@@ -110,8 +110,8 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
return false;
}
- const int startIndex = ProximityInfoUtils::getStartIndexFromCoordinates(
- MAX_PROXIMITY_CHARS_SIZE, x, y, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH);
+ const int startIndex = ProximityInfoUtils::getStartIndexFromCoordinates(x, y,
+ CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH);
if (DEBUG_PROXIMITY_INFO) {
AKLOGI("hasSpaceProximity: index %d, %d, %d", startIndex, x, y);
}
diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h
index 6d571d7bb..f3a68e4f2 100644
--- a/native/jni/src/proximity_info.h
+++ b/native/jni/src/proximity_info.h
@@ -47,57 +47,21 @@ class ProximityInfo {
// the radius of the key is assigned to zero.
return mSweetSpotRadii[keyIndex] > 0.0f;
}
- float getSweetSpotRadiiAt(int keyIndex) const {
- return mSweetSpotRadii[keyIndex];
- }
- float getSweetSpotCenterXAt(int keyIndex) const {
- return mSweetSpotCenterXs[keyIndex];
- }
- float getSweetSpotCenterYAt(int keyIndex) const {
- return mSweetSpotCenterYs[keyIndex];
- }
+ float getSweetSpotRadiiAt(int keyIndex) const { return mSweetSpotRadii[keyIndex]; }
+ float getSweetSpotCenterXAt(int keyIndex) const { return mSweetSpotCenterXs[keyIndex]; }
+ float getSweetSpotCenterYAt(int keyIndex) const { return mSweetSpotCenterYs[keyIndex]; }
void calculateNearbyKeyCodes(
const int x, const int y, const int primaryKey, int *inputCodes) const;
-
- bool hasTouchPositionCorrectionData() const {
- return HAS_TOUCH_POSITION_CORRECTION_DATA;
- }
-
- int getMostCommonKeyWidth() const {
- return MOST_COMMON_KEY_WIDTH;
- }
-
- int getMostCommonKeyWidthSquare() const {
- return MOST_COMMON_KEY_WIDTH_SQUARE;
- }
-
- int getKeyCount() const {
- return KEY_COUNT;
- }
-
- int getCellHeight() const {
- return CELL_HEIGHT;
- }
-
- int getCellWidth() const {
- return CELL_WIDTH;
- }
-
- int getGridWidth() const {
- return GRID_WIDTH;
- }
-
- int getGridHeight() const {
- return GRID_HEIGHT;
- }
-
- int getKeyboardWidth() const {
- return KEYBOARD_WIDTH;
- }
-
- int getKeyboardHeight() const {
- return KEYBOARD_HEIGHT;
- }
+ bool hasTouchPositionCorrectionData() const { return HAS_TOUCH_POSITION_CORRECTION_DATA; }
+ int getMostCommonKeyWidth() const { return MOST_COMMON_KEY_WIDTH; }
+ int getMostCommonKeyWidthSquare() const { return MOST_COMMON_KEY_WIDTH_SQUARE; }
+ int getKeyCount() const { return KEY_COUNT; }
+ int getCellHeight() const { return CELL_HEIGHT; }
+ int getCellWidth() const { return CELL_WIDTH; }
+ int getGridWidth() const { return GRID_WIDTH; }
+ int getGridHeight() const { return GRID_HEIGHT; }
+ int getKeyboardWidth() const { return KEYBOARD_WIDTH; }
+ int getKeyboardHeight() const { return KEYBOARD_HEIGHT; }
int getKeyCenterXOfCodePointG(int charCode) const;
int getKeyCenterYOfCodePointG(int charCode) const;
@@ -109,9 +73,8 @@ class ProximityInfo {
const int *const inputYCoordinates, const int inputSize, int *allInputCodes) const {
ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
inputSize, mKeyXCoordinates, mKeyYCoordinates, mKeyWidths, mKeyHeights,
- mProximityCharsArray, MAX_PROXIMITY_CHARS_SIZE, CELL_HEIGHT, CELL_WIDTH,
- GRID_WIDTH, MOST_COMMON_KEY_WIDTH, KEY_COUNT, mLocaleStr, &mCodeToKeyMap,
- allInputCodes);
+ mProximityCharsArray, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH, MOST_COMMON_KEY_WIDTH,
+ KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes);
}
int getKeyIndexOf(const int c) const {
diff --git a/native/jni/src/proximity_info_params.cpp b/native/jni/src/proximity_info_params.cpp
index 5a51f62d9..f7b3d4d71 100644
--- a/native/jni/src/proximity_info_params.cpp
+++ b/native/jni/src/proximity_info_params.cpp
@@ -25,6 +25,20 @@ const int ProximityInfoParams::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2
const int ProximityInfoParams::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
const float ProximityInfoParams::NOT_A_DISTANCE_FLOAT = -1.0f;
+
+// Per method constants
+const float ProximityInfoParams::NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f;
+const float ProximityInfoParams::NEAR_KEY_THRESHOLD_FOR_DISTANCE = 2.0f;
+const float ProximityInfoParams::MARGIN_FOR_PREV_LOCAL_MIN = 0.01f;
+const int ProximityInfoParams::DISTANCE_BASE_SCALE = 100;
+const float ProximityInfoParams::NEAR_KEY_THRESHOLD_FOR_POINT_SCORE = 0.6f;
+const int ProximityInfoParams::CORNER_CHECK_DISTANCE_THRESHOLD_SCALE = 25;
+const float ProximityInfoParams::NOT_LOCALMIN_DISTANCE_SCORE = -1.0f;
+const float ProximityInfoParams::LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE = 1.0f;
+const float ProximityInfoParams::CORNER_ANGLE_THRESHOLD_FOR_POINT_SCORE = M_PI_F * 2.0f / 3.0f;
+const float ProximityInfoParams::CORNER_SUM_ANGLE_THRESHOLD = M_PI_F / 4.0f;
+const float ProximityInfoParams::CORNER_SCORE = 1.0f;
+
// TODO: Investigate if this is required
const float ProximityInfoParams::SEARCH_KEY_RADIUS_RATIO = 0.95f;
} // namespace latinime
diff --git a/native/jni/src/proximity_info_params.h b/native/jni/src/proximity_info_params.h
index b941fec0b..978b99917 100644
--- a/native/jni/src/proximity_info_params.h
+++ b/native/jni/src/proximity_info_params.h
@@ -30,6 +30,26 @@ class ProximityInfoParams {
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR;
static const float NOT_A_DISTANCE_FLOAT;
static const float SEARCH_KEY_RADIUS_RATIO;
+
+ // Used by ProximityInfoStateUtils::initGeometricDistanceInfos()
+ static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD;
+
+ // Used by ProximityInfoStateUtils::updateNearKeysDistances()
+ static const float NEAR_KEY_THRESHOLD_FOR_DISTANCE;
+
+ // Used by ProximityInfoStateUtils::isPrevLocalMin()
+ static const float MARGIN_FOR_PREV_LOCAL_MIN;
+
+ // Used by ProximityInfoStateUtils::getPointScore()
+ static const int DISTANCE_BASE_SCALE;
+ static const float NEAR_KEY_THRESHOLD_FOR_POINT_SCORE;
+ static const int CORNER_CHECK_DISTANCE_THRESHOLD_SCALE;
+ static const float NOT_LOCALMIN_DISTANCE_SCORE;
+ static const float LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE;
+ static const float CORNER_ANGLE_THRESHOLD_FOR_POINT_SCORE;
+ static const float CORNER_SUM_ANGLE_THRESHOLD;
+ static const float CORNER_SCORE;
+
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoParams);
static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index 141be2688..fbdc2c816 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -246,11 +246,6 @@ ProximityType ProximityInfoState::getMatchedProximityId(const int index, const i
return UNRELATED_CHAR;
}
-int ProximityInfoState::getSpaceY() const {
- const int keyId = mProximityInfo->getKeyIndexOf(KEYCODE_SPACE);
- return mProximityInfo->getKeyCenterYOfKeyIdG(keyId);
-}
-
// Puts possible characters into filter and returns new filter size.
int ProximityInfoState::getAllPossibleChars(
const size_t index, int *const filter, const int filterSize) const {
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index ff1b35089..0386450bd 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -155,8 +155,6 @@ class ProximityInfoState {
ProximityType getMatchedProximityId(const int index, const int c,
const bool checkProximityChars, int *proximityIndex = 0) const;
- int getSpaceY() const;
-
int getAllPossibleChars(const size_t startIndex, int *const filter, const int filterSize) const;
float getSpeedRate(const int index) const {
diff --git a/native/jni/src/proximity_info_state_utils.cpp b/native/jni/src/proximity_info_state_utils.cpp
index 9f85743e5..da3f03deb 100644
--- a/native/jni/src/proximity_info_state_utils.cpp
+++ b/native/jni/src/proximity_info_state_utils.cpp
@@ -138,13 +138,13 @@ namespace latinime {
return inputProximities + (index * MAX_PROXIMITY_CHARS_SIZE);
}
-/* static */ int ProximityInfoStateUtils::getPrimaryCodePointAt(
- const int *const inputProximities, const int index) {
+/* static */ int ProximityInfoStateUtils::getPrimaryCodePointAt(const int *const inputProximities,
+ const int index) {
return getProximityCodePointsAt(inputProximities, index)[0];
}
-/* static */ void ProximityInfoStateUtils::initPrimaryInputWord(
- const int inputSize, const int *const inputProximities, int *primaryInputWord) {
+/* static */ void ProximityInfoStateUtils::initPrimaryInputWord(const int inputSize,
+ const int *const inputProximities, int *primaryInputWord) {
memset(primaryInputWord, 0, sizeof(primaryInputWord[0]) * MAX_WORD_LENGTH);
for (int i = 0; i < inputSize; ++i) {
primaryInputWord[i] = getPrimaryCodePointAt(inputProximities, i);
@@ -153,8 +153,7 @@ namespace latinime {
/* static */ float ProximityInfoStateUtils::calculateSquaredDistanceFromSweetSpotCenter(
const ProximityInfo *const proximityInfo, const std::vector<int> *const sampledInputXs,
- const std::vector<int> *const sampledInputYs, const int keyIndex,
- const int inputIndex) {
+ const std::vector<int> *const sampledInputYs, const int keyIndex, const int inputIndex) {
const float sweetSpotCenterX = proximityInfo->getSweetSpotCenterXAt(keyIndex);
const float sweetSpotCenterY = proximityInfo->getSweetSpotCenterYAt(keyIndex);
const float inputX = static_cast<float>((*sampledInputXs)[inputIndex]);
@@ -164,8 +163,7 @@ namespace latinime {
/* static */ float ProximityInfoStateUtils::calculateNormalizedSquaredDistance(
const ProximityInfo *const proximityInfo, const std::vector<int> *const sampledInputXs,
- const std::vector<int> *const sampledInputYs,
- const int keyIndex, const int inputIndex) {
+ const std::vector<int> *const sampledInputYs, const int keyIndex, const int inputIndex) {
if (keyIndex == NOT_AN_INDEX) {
return ProximityInfoParams::NOT_A_DISTANCE_FLOAT;
}
@@ -182,11 +180,9 @@ namespace latinime {
}
/* static */ void ProximityInfoStateUtils::initNormalizedSquaredDistances(
- const ProximityInfo *const proximityInfo, const int inputSize,
- const int *inputXCoordinates, const int *inputYCoordinates,
- const int *const inputProximities,
- const std::vector<int> *const sampledInputXs,
- const std::vector<int> *const sampledInputYs,
+ const ProximityInfo *const proximityInfo, const int inputSize, const int *inputXCoordinates,
+ const int *inputYCoordinates, const int *const inputProximities,
+ const std::vector<int> *const sampledInputXs, const std::vector<int> *const sampledInputYs,
int *normalizedSquaredDistances) {
memset(normalizedSquaredDistances, NOT_A_DISTANCE,
sizeof(normalizedSquaredDistances[0]) * MAX_PROXIMITY_CHARS_SIZE * MAX_WORD_LENGTH);
@@ -201,8 +197,7 @@ namespace latinime {
a += 0;
AKLOGI("--- Primary = %c, x = %d, y = %d", primaryKey, x, y);
}
- for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityCodePoints[j] > 0;
- ++j) {
+ for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE && proximityCodePoints[j] > 0; ++j) {
const int currentCodePoint = proximityCodePoints[j];
const float squaredDistance =
hasInputCoordinates ? calculateNormalizedSquaredDistance(
@@ -211,7 +206,7 @@ namespace latinime {
ProximityInfoParams::NOT_A_DISTANCE_FLOAT;
if (squaredDistance >= 0.0f) {
normalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] =
- (int) (squaredDistance
+ static_cast<int>(squaredDistance
* ProximityInfoParams::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR);
} else {
normalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] =
@@ -227,9 +222,8 @@ namespace latinime {
}
/* static */ void ProximityInfoStateUtils::initGeometricDistanceInfos(
- const ProximityInfo *const proximityInfo, const int keyCount,
- const int sampledInputSize, const int lastSavedInputSize,
- const std::vector<int> *const sampledInputXs,
+ const ProximityInfo *const proximityInfo, const int keyCount, const int sampledInputSize,
+ const int lastSavedInputSize, const std::vector<int> *const sampledInputXs,
const std::vector<int> *const sampledInputYs,
std::vector<NearKeycodesSet> *SampledNearKeysVector,
std::vector<float> *SampledDistanceCache_G) {
@@ -237,7 +231,6 @@ namespace latinime {
SampledDistanceCache_G->resize(sampledInputSize * keyCount);
for (int i = lastSavedInputSize; i < sampledInputSize; ++i) {
(*SampledNearKeysVector)[i].reset();
- static const float NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD = 4.0f;
for (int k = 0; k < keyCount; ++k) {
const int index = i * keyCount + k;
const int x = (*sampledInputXs)[i];
@@ -245,7 +238,8 @@ namespace latinime {
const float normalizedSquaredDistance =
proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y);
(*SampledDistanceCache_G)[index] = normalizedSquaredDistance;
- if (normalizedSquaredDistance < NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD) {
+ if (normalizedSquaredDistance
+ < ProximityInfoParams::NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD) {
(*SampledNearKeysVector)[i][k] = true;
}
}
@@ -265,8 +259,7 @@ namespace latinime {
/* static */ float ProximityInfoStateUtils::refreshSpeedRates(const int inputSize,
const int *const xCoordinates, const int *const yCoordinates, const int *const times,
const int lastSavedInputSize, const int sampledInputSize,
- const std::vector<int> *const sampledInputXs,
- const std::vector<int> *const sampledInputYs,
+ const std::vector<int> *const sampledInputXs, const std::vector<int> *const sampledInputYs,
const std::vector<int> *const sampledInputTimes,
const std::vector<int> *const sampledLengthCache,
const std::vector<int> *const sampledInputIndice, std::vector<float> *sampledSpeedRates,
@@ -359,14 +352,12 @@ namespace latinime {
/* static */ float ProximityInfoStateUtils::updateNearKeysDistances(
const ProximityInfo *const proximityInfo, const float maxPointToKeyLength, const int x,
const int y, NearKeysDistanceMap *const currentNearKeysDistances) {
- static const float NEAR_KEY_THRESHOLD = 2.0f;
-
currentNearKeysDistances->clear();
const int keyCount = proximityInfo->getKeyCount();
float nearestKeyDistance = maxPointToKeyLength;
for (int k = 0; k < keyCount; ++k) {
const float dist = proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y);
- if (dist < NEAR_KEY_THRESHOLD) {
+ if (dist < ProximityInfoParams::NEAR_KEY_THRESHOLD_FOR_DISTANCE) {
currentNearKeysDistances->insert(std::pair<int, float>(k, dist));
}
if (nearestKeyDistance > dist) {
@@ -381,14 +372,15 @@ namespace latinime {
const NearKeysDistanceMap *const currentNearKeysDistances,
const NearKeysDistanceMap *const prevNearKeysDistances,
const NearKeysDistanceMap *const prevPrevNearKeysDistances) {
- static const float MARGIN = 0.01f;
-
for (NearKeysDistanceMap::const_iterator it = prevNearKeysDistances->begin();
it != prevNearKeysDistances->end(); ++it) {
NearKeysDistanceMap::const_iterator itPP = prevPrevNearKeysDistances->find(it->first);
NearKeysDistanceMap::const_iterator itC = currentNearKeysDistances->find(it->first);
- if ((itPP == prevPrevNearKeysDistances->end() || itPP->second > it->second + MARGIN)
- && (itC == currentNearKeysDistances->end() || itC->second > it->second + MARGIN)) {
+ const bool isPrevPrevNear = (itPP == prevPrevNearKeysDistances->end()
+ || itPP->second > it->second + ProximityInfoParams::MARGIN_FOR_PREV_LOCAL_MIN);
+ const bool isCurrentNear = (itC == currentNearKeysDistances->end()
+ || itC->second > it->second + ProximityInfoParams::MARGIN_FOR_PREV_LOCAL_MIN);
+ if (isPrevPrevNear && isCurrentNear) {
return true;
}
}
@@ -402,15 +394,6 @@ namespace latinime {
const NearKeysDistanceMap *const prevNearKeysDistances,
const NearKeysDistanceMap *const prevPrevNearKeysDistances,
std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs) {
- static const int DISTANCE_BASE_SCALE = 100;
- static const float NEAR_KEY_THRESHOLD = 0.6f;
- static const int CORNER_CHECK_DISTANCE_THRESHOLD_SCALE = 25;
- static const float NOT_LOCALMIN_DISTANCE_SCORE = -1.0f;
- static const float LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE = 1.0f;
- static const float CORNER_ANGLE_THRESHOLD = M_PI_F * 2.0f / 3.0f;
- static const float CORNER_SUM_ANGLE_THRESHOLD = M_PI_F / 4.0f;
- static const float CORNER_SCORE = 1.0f;
-
const size_t size = sampledInputXs->size();
// If there is only one point, add this point. Besides, if the previous point's distance map
// is empty, we re-compute nearby keys distances from the current point.
@@ -422,16 +405,17 @@ namespace latinime {
const int baseSampleRate = mostCommonKeyWidth;
const int distPrev = getDistanceInt(sampledInputXs->back(), sampledInputYs->back(),
- (*sampledInputXs)[size - 2], (*sampledInputYs)[size - 2]) * DISTANCE_BASE_SCALE;
+ (*sampledInputXs)[size - 2], (*sampledInputYs)[size - 2])
+ * ProximityInfoParams::DISTANCE_BASE_SCALE;
float score = 0.0f;
// Location
if (!isPrevLocalMin(currentNearKeysDistances, prevNearKeysDistances,
prevPrevNearKeysDistances)) {
- score += NOT_LOCALMIN_DISTANCE_SCORE;
- } else if (nearest < NEAR_KEY_THRESHOLD) {
+ score += ProximityInfoParams::NOT_LOCALMIN_DISTANCE_SCORE;
+ } else if (nearest < ProximityInfoParams::NEAR_KEY_THRESHOLD_FOR_POINT_SCORE) {
// Promote points nearby keys
- score += LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE;
+ score += ProximityInfoParams::LOCALMIN_DISTANCE_AND_NEAR_TO_KEY_SCORE;
}
// Angle
const float angle1 = getAngle(x, y, sampledInputXs->back(), sampledInputYs->back());
@@ -440,9 +424,10 @@ namespace latinime {
const float angleDiff = getAngleDiff(angle1, angle2);
// Save corner
- if (distPrev > baseSampleRate * CORNER_CHECK_DISTANCE_THRESHOLD_SCALE
- && (sumAngle > CORNER_SUM_ANGLE_THRESHOLD || angleDiff > CORNER_ANGLE_THRESHOLD)) {
- score += CORNER_SCORE;
+ if (distPrev > baseSampleRate * ProximityInfoParams::CORNER_CHECK_DISTANCE_THRESHOLD_SCALE
+ && (sumAngle > ProximityInfoParams::CORNER_SUM_ANGLE_THRESHOLD
+ || angleDiff > ProximityInfoParams::CORNER_ANGLE_THRESHOLD_FOR_POINT_SCORE)) {
+ score += ProximityInfoParams::CORNER_SCORE;
}
return score;
}
@@ -1033,7 +1018,7 @@ namespace latinime {
const ProximityInfo *const proximityInfo, const int sampledInputSize,
const std::vector<hash_map_compat<int, float> > *const charProbabilities,
int *const codePointBuf) {
- ASSERT(charProbabilities->size() >= 0 && sampledInputSize >= 0);
+ ASSERT(sampledInputSize >= 0);
memset(codePointBuf, 0, sizeof(codePointBuf[0]) * MAX_WORD_LENGTH);
static const float DEMOTION_LOG_PROBABILITY = 0.3f;
int index = 0;
diff --git a/native/jni/src/proximity_info_utils.h b/native/jni/src/proximity_info_utils.h
index 24917d879..c50df57f9 100644
--- a/native/jni/src/proximity_info_utils.h
+++ b/native/jni/src/proximity_info_utils.h
@@ -49,9 +49,9 @@ class ProximityInfoUtils {
const int *const inputXCoordinates, const int *const inputYCoordinates,
const int inputSize, const int *const keyXCoordinates,
const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights,
- const int *const proximityCharsArray, const int maxProximityCharsSize,
- const int cellHeight, const int cellWidth, const int gridWidth,
- const int mostCommonKeyWidth, const int keyCount, const char *const localeStr,
+ const int *const proximityCharsArray, const int cellHeight, const int cellWidth,
+ const int gridWidth, const int mostCommonKeyWidth, const int keyCount,
+ const char *const localeStr,
const hash_map_compat<int, int> *const codeToKeyMap, int *inputProximities) {
// Initialize
// - mInputCodes
@@ -63,9 +63,8 @@ class ProximityInfoUtils {
const int y = inputYCoordinates[i];
int *proximities = &inputProximities[i * MAX_PROXIMITY_CHARS_SIZE];
calculateProximities(keyXCoordinates, keyYCoordinates, keyWidths, keyHeights,
- proximityCharsArray, maxProximityCharsSize, cellHeight, cellWidth, gridWidth,
- mostCommonKeyWidth, keyCount, x, y, primaryKey, localeStr, codeToKeyMap,
- proximities);
+ proximityCharsArray, cellHeight, cellWidth, gridWidth, mostCommonKeyWidth,
+ keyCount, x, y, primaryKey, localeStr, codeToKeyMap, proximities);
}
if (DEBUG_PROXIMITY_CHARS) {
@@ -81,10 +80,9 @@ class ProximityInfoUtils {
}
}
- static AK_FORCE_INLINE int getStartIndexFromCoordinates(const int maxProximityCharsSize,
- const int x, const int y, const int cellHeight, const int cellWidth,
- const int gridWidth) {
- return ((y / cellHeight) * gridWidth + (x / cellWidth)) * maxProximityCharsSize;
+ static AK_FORCE_INLINE int getStartIndexFromCoordinates(const int x, const int y,
+ const int cellHeight, const int cellWidth, const int gridWidth) {
+ return ((y / cellHeight) * gridWidth + (x / cellWidth)) * MAX_PROXIMITY_CHARS_SIZE;
}
static inline float getSquaredDistanceFloat(const float x1, const float y1, const float x2,
@@ -153,21 +151,18 @@ class ProximityInfoUtils {
return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom;
}
- static void calculateProximities(
- const int *const keyXCoordinates, const int *const keyYCoordinates,
- const int *const keyWidths, const int *keyHeights,
- const int *const proximityCharsArray,
- const int maxProximityCharsSize, const int cellHeight, const int cellWidth,
+ static void calculateProximities(const int *const keyXCoordinates,
+ const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights,
+ const int *const proximityCharsArray, const int cellHeight, const int cellWidth,
const int gridWidth, const int mostCommonKeyWidth, const int keyCount,
const int x, const int y, const int primaryKey, const char *const localeStr,
const hash_map_compat<int, int> *const codeToKeyMap, int *proximities) {
const int mostCommonKeyWidthSquare = mostCommonKeyWidth * mostCommonKeyWidth;
int insertPos = 0;
proximities[insertPos++] = primaryKey;
- const int startIndex = getStartIndexFromCoordinates(
- maxProximityCharsSize, x, y, cellHeight, cellWidth, gridWidth);
+ const int startIndex = getStartIndexFromCoordinates(x, y, cellHeight, cellWidth, gridWidth);
if (startIndex >= 0) {
- for (int i = 0; i < maxProximityCharsSize; ++i) {
+ for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
const int c = proximityCharsArray[startIndex + i];
if (c < KEYCODE_SPACE || c == primaryKey) {
continue;
@@ -179,7 +174,7 @@ class ProximityInfoUtils {
keyWidths, keyHeights, keyIndex, x, y);
if (onKey || distance < mostCommonKeyWidthSquare) {
proximities[insertPos++] = c;
- if (insertPos >= maxProximityCharsSize) {
+ if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
ASSERT(false);
}
@@ -191,7 +186,7 @@ class ProximityInfoUtils {
AdditionalProximityChars::getAdditionalCharsSize(localeStr, primaryKey);
if (additionalProximitySize > 0) {
proximities[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE;
- if (insertPos >= maxProximityCharsSize) {
+ if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
ASSERT(false);
}
@@ -212,7 +207,7 @@ class ProximityInfoUtils {
continue;
}
proximities[insertPos++] = ac;
- if (insertPos >= maxProximityCharsSize) {
+ if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
ASSERT(false);
}
@@ -222,7 +217,7 @@ class ProximityInfoUtils {
}
}
// Add a delimiter for the proximity characters
- for (int i = insertPos; i < maxProximityCharsSize; ++i) {
+ for (int i = insertPos; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
proximities[i] = NOT_A_CODE_POINT;
}
}
diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h
index e0833ce4b..54e8007a2 100644
--- a/native/jni/src/words_priority_queue.h
+++ b/native/jni/src/words_priority_queue.h
@@ -63,10 +63,9 @@ class WordsPriorityQueue {
const int minScore = sw->mScore;
if (minScore >= score) {
return;
- } else {
- sw->mUsed = false;
- mSuggestions.pop();
}
+ sw->mUsed = false;
+ mSuggestions.pop();
}
if (sw == 0) {
sw = getFreeSuggestedWord(score, word, wordLength, type);
@@ -87,7 +86,7 @@ class WordsPriorityQueue {
}
}
- SuggestedWord *top() {
+ SuggestedWord *top() const {
if (mSuggestions.empty()) return 0;
SuggestedWord *sw = mSuggestions.top();
return sw;