aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src
diff options
context:
space:
mode:
Diffstat (limited to 'native/jni/src')
-rw-r--r--native/jni/src/correction.cpp2
-rw-r--r--native/jni/src/correction.h154
-rw-r--r--native/jni/src/dic_traverse_wrapper.cpp4
-rw-r--r--native/jni/src/dic_traverse_wrapper.h9
-rw-r--r--native/jni/src/dictionary.cpp2
-rw-r--r--native/jni/src/dictionary.h2
-rw-r--r--native/jni/src/gesture/gesture_decoder_wrapper.h3
-rw-r--r--native/jni/src/gesture/incremental_decoder_interface.h2
-rw-r--r--native/jni/src/gesture/incremental_decoder_wrapper.h3
-rw-r--r--native/jni/src/proximity_info.h24
-rw-r--r--native/jni/src/proximity_info_state.h7
11 files changed, 106 insertions, 106 deletions
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index e55da0113..7513b307d 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -230,7 +230,7 @@ int Correction::goDownTree(
}
// TODO: remove
-int Correction::getInputIndex() {
+int Correction::getInputIndex() const {
return mInputIndex;
}
diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h
index 57e7b7189..9899f6e66 100644
--- a/native/jni/src/correction.h
+++ b/native/jni/src/correction.h
@@ -38,63 +38,8 @@ class Correction {
NOT_ON_TERMINAL
} CorrectionType;
- /////////////////////////
- // static inline utils //
- /////////////////////////
-
- static const int TWO_31ST_DIV_255 = S_INT_MAX / 255;
- static inline int capped255MultForFullMatchAccentsOrCapitalizationDifference(const int num) {
- return (num < TWO_31ST_DIV_255 ? 255 * num : S_INT_MAX);
- }
-
- static const int TWO_31ST_DIV_2 = S_INT_MAX / 2;
- inline static void multiplyIntCapped(const int multiplier, int *base) {
- const int temp = *base;
- if (temp != S_INT_MAX) {
- // Branch if multiplier == 2 for the optimization
- if (multiplier < 0) {
- if (DEBUG_DICT) {
- assert(false);
- }
- AKLOGI("--- Invalid multiplier: %d", multiplier);
- } else if (multiplier == 0) {
- *base = 0;
- } else if (multiplier == 2) {
- *base = TWO_31ST_DIV_2 >= temp ? temp << 1 : S_INT_MAX;
- } else {
- // TODO: This overflow check gives a wrong answer when, for example,
- // temp = 2^16 + 1 and multiplier = 2^17 + 1.
- // Fix this behavior.
- const int tempRetval = temp * multiplier;
- *base = tempRetval >= temp ? tempRetval : S_INT_MAX;
- }
- }
- }
-
- inline static int powerIntCapped(const int base, const int n) {
- 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;
- }
- }
-
- inline static void multiplyRate(const int rate, int *freq) {
- if (*freq != S_INT_MAX) {
- if (*freq > 1000000) {
- *freq /= 100;
- multiplyIntCapped(rate, freq);
- } else {
- multiplyIntCapped(rate, freq);
- *freq /= 100;
- }
- }
- }
-
Correction() {};
+ virtual ~Correction();
void resetCorrection();
void initCorrection(
const ProximityInfo *pi, const int inputLength, const int maxWordLength);
@@ -108,27 +53,7 @@ class Correction {
bool sameAsTyped();
bool initProcessState(const int index);
- int getInputIndex();
-
- virtual ~Correction();
- int getSpaceProximityPos() const {
- return mSpaceProximityPos;
- }
- int getMissingSpacePos() const {
- return mMissingSpacePos;
- }
-
- int getSkipPos() const {
- return mSkipPos;
- }
-
- int getExcessivePos() const {
- return mExcessivePos;
- }
-
- int getTransposedPos() const {
- return mTransposedPos;
- }
+ int getInputIndex() const;
bool needsToPrune() const;
@@ -195,6 +120,81 @@ class Correction {
private:
DISALLOW_COPY_AND_ASSIGN(Correction);
+
+ /////////////////////////
+ // static inline utils //
+ /////////////////////////
+ static const int TWO_31ST_DIV_255 = S_INT_MAX / 255;
+ static inline int capped255MultForFullMatchAccentsOrCapitalizationDifference(const int num) {
+ return (num < TWO_31ST_DIV_255 ? 255 * num : S_INT_MAX);
+ }
+
+ static const int TWO_31ST_DIV_2 = S_INT_MAX / 2;
+ inline static void multiplyIntCapped(const int multiplier, int *base) {
+ const int temp = *base;
+ if (temp != S_INT_MAX) {
+ // Branch if multiplier == 2 for the optimization
+ if (multiplier < 0) {
+ if (DEBUG_DICT) {
+ assert(false);
+ }
+ AKLOGI("--- Invalid multiplier: %d", multiplier);
+ } else if (multiplier == 0) {
+ *base = 0;
+ } else if (multiplier == 2) {
+ *base = TWO_31ST_DIV_2 >= temp ? temp << 1 : S_INT_MAX;
+ } else {
+ // TODO: This overflow check gives a wrong answer when, for example,
+ // temp = 2^16 + 1 and multiplier = 2^17 + 1.
+ // Fix this behavior.
+ const int tempRetval = temp * multiplier;
+ *base = tempRetval >= temp ? tempRetval : S_INT_MAX;
+ }
+ }
+ }
+
+ inline static int powerIntCapped(const int base, const int n) {
+ 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;
+ }
+ }
+
+ inline static void multiplyRate(const int rate, int *freq) {
+ if (*freq != S_INT_MAX) {
+ if (*freq > 1000000) {
+ *freq /= 100;
+ multiplyIntCapped(rate, freq);
+ } else {
+ multiplyIntCapped(rate, freq);
+ *freq /= 100;
+ }
+ }
+ }
+
+ inline int getSpaceProximityPos() const {
+ return mSpaceProximityPos;
+ }
+ inline int getMissingSpacePos() const {
+ return mMissingSpacePos;
+ }
+
+ inline int getSkipPos() const {
+ return mSkipPos;
+ }
+
+ inline int getExcessivePos() const {
+ return mExcessivePos;
+ }
+
+ inline int getTransposedPos() const {
+ return mTransposedPos;
+ }
+
inline void incrementInputIndex();
inline void incrementOutputIndex();
inline void startToTraverseAllNodes();
diff --git a/native/jni/src/dic_traverse_wrapper.cpp b/native/jni/src/dic_traverse_wrapper.cpp
index 1f7dcbfb2..88ca9fa0d 100644
--- a/native/jni/src/dic_traverse_wrapper.cpp
+++ b/native/jni/src/dic_traverse_wrapper.cpp
@@ -19,8 +19,8 @@
#include "dic_traverse_wrapper.h"
namespace latinime {
-void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)(JNIEnv *env, jstring locale) = 0;
+void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring) = 0;
void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
void (*DicTraverseWrapper::sDicTraverseSessionInitMethod)(
- void *, Dictionary *, const int *, const int) = 0;
+ void *, const Dictionary *const, const int *, const int) = 0;
} // namespace latinime
diff --git a/native/jni/src/dic_traverse_wrapper.h b/native/jni/src/dic_traverse_wrapper.h
index 8396d0027..292382487 100644
--- a/native/jni/src/dic_traverse_wrapper.h
+++ b/native/jni/src/dic_traverse_wrapper.h
@@ -34,7 +34,7 @@ class DicTraverseWrapper {
return 0;
}
static void initDicTraverseSession(void *traverseSession,
- Dictionary *dictionary, const int *prevWord, const int prevWordLength) {
+ const Dictionary *const dictionary, const int *prevWord, const int prevWordLength) {
if (sDicTraverseSessionInitMethod) {
sDicTraverseSessionInitMethod(traverseSession, dictionary, prevWord, prevWordLength);
}
@@ -45,11 +45,11 @@ class DicTraverseWrapper {
}
}
static void setTraverseSessionFactoryMethod(
- void *(*factoryMethod)(JNIEnv *env, jstring locale)) {
+ void *(*factoryMethod)(JNIEnv *, jstring)) {
sDicTraverseSessionFactoryMethod = factoryMethod;
}
static void setTraverseSessionInitMethod(
- void (*initMethod)(void *, Dictionary *, const int *, const int)) {
+ void (*initMethod)(void *, const Dictionary *const, const int *, const int)) {
sDicTraverseSessionInitMethod = initMethod;
}
static void setTraverseSessionReleaseMethod(void (*releaseMethod)(void *)) {
@@ -58,7 +58,8 @@ class DicTraverseWrapper {
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
static void *(*sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring);
- static void (*sDicTraverseSessionInitMethod)(void *, Dictionary *, const int *, const int);
+ static void (*sDicTraverseSessionInitMethod)(
+ void *, const Dictionary *const, const int *, const int);
static void (*sDicTraverseSessionReleaseMethod)(void *);
};
int register_DicTraverseSession(JNIEnv *env);
diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp
index 158c3fb22..8ce8c8ba6 100644
--- a/native/jni/src/dictionary.cpp
+++ b/native/jni/src/dictionary.cpp
@@ -60,7 +60,7 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi
int *codes, int codesSize, int *prevWordChars,
int prevWordLength, int commitPoint, bool isGesture,
bool useFullEditDistance, unsigned short *outWords,
- int *frequencies, int *spaceIndices, int *outputTypes) {
+ int *frequencies, int *spaceIndices, int *outputTypes) const {
int result = 0;
if (isGesture) {
DicTraverseWrapper::initDicTraverseSession(
diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h
index fd9e77011..e9a03ce55 100644
--- a/native/jni/src/dictionary.h
+++ b/native/jni/src/dictionary.h
@@ -48,7 +48,7 @@ class Dictionary {
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,
int *prevWordChars, int prevWordLength, int commitPoint, bool isGesture,
bool useFullEditDistance, unsigned short *outWords,
- int *frequencies, int *spaceIndices, int *outputTypes);
+ int *frequencies, int *spaceIndices, int *outputTypes) const;
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
unsigned short *outWords, int *frequencies, int *outputTypes) const;
diff --git a/native/jni/src/gesture/gesture_decoder_wrapper.h b/native/jni/src/gesture/gesture_decoder_wrapper.h
index f8bfe7c79..2f6220b92 100644
--- a/native/jni/src/gesture/gesture_decoder_wrapper.h
+++ b/native/jni/src/gesture/gesture_decoder_wrapper.h
@@ -39,7 +39,8 @@ class GestureDecoderWrapper : public IncrementalDecoderInterface {
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
- unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) {
+ unsigned short *outWords, int *frequencies, int *outputIndices,
+ int *outputTypes) const {
if (!mIncrementalDecoderInterface) {
return 0;
}
diff --git a/native/jni/src/gesture/incremental_decoder_interface.h b/native/jni/src/gesture/incremental_decoder_interface.h
index 04f0095e0..d1395aab9 100644
--- a/native/jni/src/gesture/incremental_decoder_interface.h
+++ b/native/jni/src/gesture/incremental_decoder_interface.h
@@ -31,7 +31,7 @@ class IncrementalDecoderInterface {
virtual int getSuggestions(ProximityInfo *pInfo, void *traverseSession,
int *inputXs, int *inputYs, int *times, int *pointerIds, int *codes,
int inputSize, int commitPoint, unsigned short *outWords, int *frequencies,
- int *outputIndices, int *outputTypes) = 0;
+ int *outputIndices, int *outputTypes) const = 0;
IncrementalDecoderInterface() { };
virtual ~IncrementalDecoderInterface() { };
private:
diff --git a/native/jni/src/gesture/incremental_decoder_wrapper.h b/native/jni/src/gesture/incremental_decoder_wrapper.h
index 5cb2ee368..1f4d8a047 100644
--- a/native/jni/src/gesture/incremental_decoder_wrapper.h
+++ b/native/jni/src/gesture/incremental_decoder_wrapper.h
@@ -39,7 +39,8 @@ class IncrementalDecoderWrapper : public IncrementalDecoderInterface {
int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
- unsigned short *outWords, int *frequencies, int *outputIndices, int *outputTypes) {
+ unsigned short *outWords, int *frequencies, int *outputIndices,
+ int *outputTypes) const {
if (!mIncrementalDecoderInterface) {
return 0;
}
diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h
index 8a407e71a..7ee633ba8 100644
--- a/native/jni/src/proximity_info.h
+++ b/native/jni/src/proximity_info.h
@@ -41,21 +41,12 @@ class ProximityInfo {
float getNormalizedSquaredDistanceFromCenterFloat(
const int keyId, const int x, const int y) const;
bool sameAsTyped(const unsigned short *word, int length) const;
- int squaredDistanceToEdge(const int keyId, const int x, const int y) const;
- bool isOnKey(const int keyId, const int x, const int y) const {
- if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case
- const int left = mKeyXCoordinates[keyId];
- const int top = mKeyYCoordinates[keyId];
- const int right = left + mKeyWidths[keyId] + 1;
- const int bottom = top + mKeyHeights[keyId];
- return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom;
- }
int getKeyIndex(const int c) const;
int getKeyCode(const int keyIndex) const;
bool hasSweetSpotData(const int keyIndex) const {
// When there are no calibration data for a key,
// the radius of the key is assigned to zero.
- return mSweetSpotRadii[keyIndex] > 0.0;
+ return mSweetSpotRadii[keyIndex] > 0.0f;
}
float getSweetSpotRadiiAt(int keyIndex) const {
return mSweetSpotRadii[keyIndex];
@@ -111,10 +102,6 @@ class ProximityInfo {
float getKeyCenterYOfIdG(int keyId) const;
int getKeyKeyDistanceG(int key0, int key1) const;
- // Returns the keyboard key-center information.
- void getCenters(int *centersX, int *centersY, int *codeToKeyIndex, int *keyToCodeIndex,
- int *keyCount, int *keyWidth) const;
-
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
// The max number of the keys in one keyboard layout
@@ -131,6 +118,15 @@ class ProximityInfo {
float calculateSquaredDistanceFromSweetSpotCenter(
const int keyIndex, const int inputIndex) const;
bool hasInputCoordinates() const;
+ int squaredDistanceToEdge(const int keyId, const int x, const int y) const;
+ bool isOnKey(const int keyId, const int x, const int y) const {
+ if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case
+ const int left = mKeyXCoordinates[keyId];
+ const int top = mKeyYCoordinates[keyId];
+ const int right = left + mKeyWidths[keyId] + 1;
+ const int bottom = top + mKeyHeights[keyId];
+ return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom;
+ }
const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH;
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index 474c40757..2fb0ae044 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -48,9 +48,6 @@ class ProximityInfoState {
// Defined here //
/////////////////////////////////////////
ProximityInfoState() {};
- inline const int *getProximityCharsAt(const int index) const {
- return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE_INTERNAL);
- }
inline unsigned short getPrimaryCharAt(const int index) const {
return getProximityCharsAt(index)[0];
@@ -194,6 +191,10 @@ class ProximityInfoState {
return mInputXCoordinates && mInputYCoordinates;
}
+ inline const int *getProximityCharsAt(const int index) const {
+ return mInputCodes + (index * MAX_PROXIMITY_CHARS_SIZE_INTERNAL);
+ }
+
// const
const ProximityInfo *mProximityInfo;
bool mHasTouchPositionCorrectionData;