am fee0ac60
: Cleanup and fix method visibility.
* commit 'fee0ac60b1cd0a4760ca8f310ff8a86b925d833b': Cleanup and fix method visibility.
This commit is contained in:
commit
0acb132669
4 changed files with 92 additions and 95 deletions
|
@ -230,7 +230,7 @@ int Correction::goDownTree(
|
|||
}
|
||||
|
||||
// TODO: remove
|
||||
int Correction::getInputIndex() {
|
||||
int Correction::getInputIndex() const {
|
||||
return mInputIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue