Cleanup getProximityType

Change-Id: I89c5871bbcf0fe3d5f50052e8f64932d8efbce94
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index d4bd4aa..b8690eb 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -214,7 +214,7 @@
         bool incremented = false;
         if (mLastCharExceeded && mInputIndex == mInputSize - 1) {
             // TODO: Do not check the proximity if EditDistance exceeds the threshold
-            const ProximityType matchId = mProximityInfoState.getMatchedProximityId(
+            const ProximityType matchId = mProximityInfoState.getProximityType(
                     mInputIndex, c, true, &proximityIndex);
             if (isEquivalentChar(matchId)) {
                 mLastCharExceeded = false;
@@ -268,7 +268,7 @@
 
     bool secondTransposing = false;
     if (mTransposedCount % 2 == 1) {
-        if (isEquivalentChar(mProximityInfoState.getMatchedProximityId(
+        if (isEquivalentChar(mProximityInfoState.getProximityType(
                 mInputIndex - 1, c, false))) {
             ++mTransposedCount;
             secondTransposing = true;
@@ -300,7 +300,7 @@
 
     ProximityType matchedProximityCharId = secondTransposing
             ? EQUIVALENT_CHAR
-            : mProximityInfoState.getMatchedProximityId(
+            : mProximityInfoState.getProximityType(
                     mInputIndex, c, checkProximityChars, &proximityIndex);
 
     if (UNRELATED_CHAR == matchedProximityCharId
@@ -308,7 +308,7 @@
         if (canTryCorrection && mOutputIndex > 0
                 && mCorrectionStates[mOutputIndex].mProximityMatching
                 && mCorrectionStates[mOutputIndex].mExceeding
-                && isEquivalentChar(mProximityInfoState.getMatchedProximityId(
+                && isEquivalentChar(mProximityInfoState.getProximityType(
                         mInputIndex, mWord[mOutputIndex - 1], false))) {
             if (DEBUG_CORRECTION
                     && (INPUTLENGTH_FOR_DEBUG <= 0 || INPUTLENGTH_FOR_DEBUG == mInputSize)
@@ -327,7 +327,7 @@
             // Here, we are doing something equivalent to matchedProximityCharId,
             // but we already know that "excessive char correction" just happened
             // so that we just need to check "mProximityCount == 0".
-            matchedProximityCharId = mProximityInfoState.getMatchedProximityId(
+            matchedProximityCharId = mProximityInfoState.getProximityType(
                     mInputIndex, c, mProximityCount == 0, &proximityIndex);
         }
     }
@@ -344,10 +344,10 @@
         if (mInputIndex < mInputSize - 1 && mOutputIndex > 0 && mTransposedCount > 0
                 && !mCorrectionStates[mOutputIndex].mTransposing
                 && mCorrectionStates[mOutputIndex - 1].mTransposing
-                && isEquivalentChar(mProximityInfoState.getMatchedProximityId(
+                && isEquivalentChar(mProximityInfoState.getProximityType(
                         mInputIndex, mWord[mOutputIndex - 1], false))
                 && isEquivalentChar(
-                        mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
+                        mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
             // Conversion t->e
             // Example:
             // occaisional -> occa   sional
@@ -359,7 +359,7 @@
                 && !mCorrectionStates[mOutputIndex].mTransposing
                 && mCorrectionStates[mOutputIndex - 1].mTransposing
                 && isEquivalentChar(
-                        mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
+                        mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) {
             // Conversion t->s
             // Example:
             // chcolate -> chocolate
@@ -371,7 +371,7 @@
                 && mCorrectionStates[mOutputIndex].mProximityMatching
                 && mCorrectionStates[mOutputIndex].mSkipping
                 && isEquivalentChar(
-                        mProximityInfoState.getMatchedProximityId(mInputIndex - 1, c, false))) {
+                        mProximityInfoState.getProximityType(mInputIndex - 1, c, false))) {
             // Conversion p->s
             // Note: This logic tries saving cases like contrst --> contrast -- "a" is one of
             // proximity chars of "s", but it should rather be handled as a skipped char.
@@ -383,7 +383,7 @@
                 && mCorrectionStates[mOutputIndex].mSkipping
                 && mCorrectionStates[mOutputIndex].mAdditionalProximityMatching
                 && isProximityCharOrEquivalentChar(
-                        mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
+                        mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
             // Conversion s->a
             incrementInputIndex();
             --mSkippedCount;
@@ -392,7 +392,7 @@
             mDistances[mOutputIndex] = ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO;
         } else if ((mExceeding || mTransposing) && mInputIndex - 1 < mInputSize
                 && isEquivalentChar(
-                        mProximityInfoState.getMatchedProximityId(mInputIndex + 1, c, false))) {
+                        mProximityInfoState.getProximityType(mInputIndex + 1, c, false))) {
             // 1.2. Excessive or transpose correction
             if (mTransposing) {
                 ++mTransposedCount;
@@ -614,7 +614,7 @@
         multiplyIntCapped(matchWeight, &finalFreq);
     }
 
-    if (proximityInfoState->getMatchedProximityId(0, word[0], true) == UNRELATED_CHAR) {
+    if (proximityInfoState->getProximityType(0, word[0], true) == UNRELATED_CHAR) {
         multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq);
     }
 
diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h
index 22bbdf1..57a175d 100644
--- a/native/jni/src/proximity_info.h
+++ b/native/jni/src/proximity_info.h
@@ -70,7 +70,7 @@
     int getKeyCenterYOfKeyIdG(int keyId) const;
     int getKeyKeyDistanceG(int keyId0, int keyId1) const;
 
-    void AK_FORCE_INLINE initializeProximities(const int *const inputCodes,
+    AK_FORCE_INLINE void initializeProximities(const int *const inputCodes,
             const int *const inputXCoordinates, const int *const inputYCoordinates,
             const int inputSize, int *allInputCodes) const {
         ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
@@ -79,10 +79,14 @@
                 KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes);
     }
 
-    int AK_FORCE_INLINE getKeyIndexOf(const int c) const {
+    AK_FORCE_INLINE int getKeyIndexOf(const int c) const {
         return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap);
     }
 
+    AK_FORCE_INLINE bool isCodePointOnKeyboard(const int codePoint) const {
+        return getKeyIndexOf(codePoint) != NOT_AN_INDEX;
+    }
+
  private:
     DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
 
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index d13248c..3ecaade 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -193,20 +193,20 @@
 // the same position. We want to see if c is in it: if so, then the word contains at that position
 // a character close to what the user typed.
 // What the user typed is actually the first character of the array.
-// proximityIndex is a pointer to the variable where getMatchedProximityId returns the index of c
+// proximityIndex is a pointer to the variable where getProximityType returns the index of c
 // in the proximity chars of the input index.
 // Notice : accented characters do not have a proximity list, so they are alone in their list. The
 // non-accented version of the character should be considered "close", but not the other keys close
 // to the non-accented version.
-ProximityType ProximityInfoState::getMatchedProximityId(const int index, const int c,
+ProximityType ProximityInfoState::getProximityType(const int index, const int codePoint,
         const bool checkProximityChars, int *proximityIndex) const {
     const int *currentCodePoints = getProximityCodePointsAt(index);
     const int firstCodePoint = currentCodePoints[0];
-    const int baseLowerC = toBaseLowerCase(c);
+    const int baseLowerC = toBaseLowerCase(codePoint);
 
     // The first char in the array is what user typed. If it matches right away, that means the
     // user typed that same char for this pos.
-    if (firstCodePoint == baseLowerC || firstCodePoint == c) {
+    if (firstCodePoint == baseLowerC || firstCodePoint == codePoint) {
         return EQUIVALENT_CHAR;
     }
 
@@ -222,7 +222,8 @@
     int j = 1;
     while (j < MAX_PROXIMITY_CHARS_SIZE
             && currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
-        const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c);
+        const bool matched = (currentCodePoints[j] == baseLowerC
+                || currentCodePoints[j] == codePoint);
         if (matched) {
             if (proximityIndex) {
                 *proximityIndex = j;
@@ -236,7 +237,8 @@
         ++j;
         while (j < MAX_PROXIMITY_CHARS_SIZE
                 && currentCodePoints[j] > ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) {
-            const bool matched = (currentCodePoints[j] == baseLowerC || currentCodePoints[j] == c);
+            const bool matched = (currentCodePoints[j] == baseLowerC
+                    || currentCodePoints[j] == codePoint);
             if (matched) {
                 if (proximityIndex) {
                     *proximityIndex = j;
@@ -250,6 +252,21 @@
     return UNRELATED_CHAR;
 }
 
+ProximityType ProximityInfoState::getProximityTypeG(const int index, const int codePoint) const {
+    if (!isUsed()) {
+        return UNRELATED_NOR_SUBSTITUTION_CHAR;
+    }
+    const int lowerCodePoint = toLowerCase(codePoint);
+    const int baseLowerCodePoint = toBaseCodePoint(lowerCodePoint);
+    for (int i = 0; i < static_cast<int>(mSampledSearchKeyVectors[index].size()); ++i) {
+        if (mSampledSearchKeyVectors[index][i] == lowerCodePoint
+                || mSampledSearchKeyVectors[index][i] == baseLowerCodePoint) {
+            return EQUIVALENT_CHAR;
+        }
+    }
+    return UNRELATED_NOR_SUBSTITUTION_CHAR;
+}
+
 bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const {
     ASSERT(keyId >= 0 && index >= 0 && index < mSampledInputSize);
     return mSampledSearchKeySets[index].test(keyId);
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index c4cbd58..dd1eb76 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -152,9 +152,11 @@
     float getPointToKeyLength(const int inputIndex, const int codePoint, const float scale) const;
     float getPointToKeyLength_G(const int inputIndex, const int codePoint) const;
 
-    ProximityType getMatchedProximityId(const int index, const int c,
+    ProximityType getProximityType(const int index, const int codePoint,
             const bool checkProximityChars, int *proximityIndex = 0) const;
 
+    ProximityType getProximityTypeG(const int index, const int codePoint) const;
+
     const std::vector<int> *getSearchKeyVector(const int index) const {
         return &mSampledSearchKeyVectors[index];
     }