diff options
Diffstat (limited to 'native/jni')
23 files changed, 86 insertions, 74 deletions
diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 3b3da96cc..9657b9d65 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -31,15 +31,12 @@ LOCAL_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-ali -Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls \ -Woverloaded-virtual -Wstrict-null-sentinel -Wsign-promo -Wno-system-headers -ifeq ($(TARGET_ARCH), arm) -ifeq ($(TARGET_GCC_VERSION), 4.6) -LOCAL_CFLAGS += -Winline -endif # TARGET_GCC_VERSION -endif # TARGET_ARCH - # To suppress compiler warnings for unused variables/functions used for debug features etc. LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function +# For C++11 +LOCAL_CFLAGS += -std=c++11 + include $(LOCAL_PATH)/NativeFileList.mk LOCAL_SRC_FILES := \ @@ -64,7 +61,7 @@ LOCAL_MODULE := libjni_latinime_common_static LOCAL_MODULE_TAGS := optional LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := stlport_static +LOCAL_NDK_STL_VARIANT := gnustl_static include $(BUILD_STATIC_LIBRARY) ###################################### @@ -87,7 +84,7 @@ LOCAL_MODULE := libjni_latinime LOCAL_MODULE_TAGS := optional LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := stlport_static +LOCAL_NDK_STL_VARIANT := gnustl_static LOCAL_LDFLAGS += -ldl include $(BUILD_SHARED_LIBRARY) diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk index 82237dc24..1f5824608 100644 --- a/native/jni/NativeFileList.mk +++ b/native/jni/NativeFileList.mk @@ -32,7 +32,6 @@ LATIN_IME_CORE_SRC_FILES := \ digraph_utils.cpp \ error_type_utils.cpp \ multi_bigram_map.cpp \ - suggestions_output_utils.cpp \ word_property.cpp) \ $(addprefix suggest/core/layout/, \ additional_proximity_chars.cpp \ @@ -41,6 +40,7 @@ LATIN_IME_CORE_SRC_FILES := \ proximity_info_state.cpp \ proximity_info_state_utils.cpp) \ suggest/core/policy/weighting.cpp \ + suggest/core/result/suggestions_output_utils.cpp \ suggest/core/session/dic_traverse_session.cpp \ $(addprefix suggest/policyimpl/dictionary/, \ header/header_policy.cpp \ diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index 22cc4c02b..4c57af0ba 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -344,21 +344,18 @@ static inline void prof_out(void) { #define MAX_POINTER_COUNT 1 #define MAX_POINTER_COUNT_G 2 -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; } - // DEBUG #define INPUTLENGTH_FOR_DEBUG (-1) #define MIN_OUTPUT_INDEX_FOR_DEBUG (-1) #define DISALLOW_DEFAULT_CONSTRUCTOR(TypeName) \ - TypeName() + TypeName() = delete #define DISALLOW_COPY_CONSTRUCTOR(TypeName) \ - TypeName(const TypeName&) + TypeName(const TypeName&) = delete #define DISALLOW_ASSIGNMENT_OPERATOR(TypeName) \ - void operator=(const TypeName&) + void operator=(const TypeName&) = delete #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ DISALLOW_COPY_CONSTRUCTOR(TypeName); \ diff --git a/native/jni/src/suggest/core/dicnode/dic_node_priority_queue.h b/native/jni/src/suggest/core/dicnode/dic_node_priority_queue.h index 7461f0cc6..1f02731a5 100644 --- a/native/jni/src/suggest/core/dicnode/dic_node_priority_queue.h +++ b/native/jni/src/suggest/core/dicnode/dic_node_priority_queue.h @@ -17,6 +17,7 @@ #ifndef LATINIME_DIC_NODE_PRIORITY_QUEUE_H #define LATINIME_DIC_NODE_PRIORITY_QUEUE_H +#include <algorithm> #include <queue> #include <vector> @@ -49,7 +50,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener { AK_FORCE_INLINE void setMaxSize(const int maxSize) { ASSERT(maxSize <= mCapacity); - mMaxSize = min(maxSize, mCapacity); + mMaxSize = std::min(maxSize, mCapacity); } AK_FORCE_INLINE void clearAndResizeToCapacity() { diff --git a/native/jni/src/suggest/core/dicnode/dic_node_utils.cpp b/native/jni/src/suggest/core/dicnode/dic_node_utils.cpp index 71bcab6cb..a6ea68c29 100644 --- a/native/jni/src/suggest/core/dicnode/dic_node_utils.cpp +++ b/native/jni/src/suggest/core/dicnode/dic_node_utils.cpp @@ -16,6 +16,7 @@ #include "suggest/core/dicnode/dic_node_utils.h" +#include <algorithm> #include <cstring> #include "suggest/core/dicnode/dic_node.h" @@ -117,7 +118,7 @@ namespace latinime { } actualLength0 = i + 1; } - actualLength0 = min(actualLength0, MAX_WORD_LENGTH); + actualLength0 = std::min(actualLength0, MAX_WORD_LENGTH); memmove(dest, src0, actualLength0 * sizeof(dest[0])); if (!src1 || length1 == 0) { return actualLength0; @@ -129,7 +130,7 @@ namespace latinime { } actualLength1 = i + 1; } - actualLength1 = min(actualLength1, MAX_WORD_LENGTH - actualLength0); + actualLength1 = std::min(actualLength1, MAX_WORD_LENGTH - actualLength0); memmove(&dest[actualLength0], src1, actualLength1 * sizeof(dest[0])); return actualLength0 + actualLength1; } diff --git a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h index 8493b6a8b..c31c056f5 100644 --- a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h +++ b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h @@ -17,6 +17,7 @@ #ifndef LATINIME_DIC_NODES_CACHE_H #define LATINIME_DIC_NODES_CACHE_H +#include <algorithm> #include <stdint.h> #include "defines.h" @@ -51,7 +52,7 @@ class DicNodesCache { // We want to use the max capacity for the current active dic node queue. mActiveDicNodes->clearAndResizeToCapacity(); // nextActiveSize is used to limit the next iteration's active dic node size. - const int nextActiveSizeFittingToTheCapacity = min(nextActiveSize, getCacheCapacity()); + const int nextActiveSizeFittingToTheCapacity = std::min(nextActiveSize, getCacheCapacity()); mNextActiveDicNodes->clearAndResize(nextActiveSizeFittingToTheCapacity); mTerminalDicNodes->clearAndResize(terminalSize); // We want to use the max capacity for the cached dic nodes that will be used for the diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h index fc6851099..abafc0edf 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h @@ -17,6 +17,7 @@ #ifndef LATINIME_DIC_NODE_STATE_OUTPUT_H #define LATINIME_DIC_NODE_STATE_OUTPUT_H +#include <algorithm> #include <cstring> // for memmove() #include <stdint.h> @@ -49,7 +50,8 @@ class DicNodeStateOutput { void addMergedNodeCodePoints(const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { if (mergedNodeCodePoints) { - const int additionalCodePointCount = min(static_cast<int>(mergedNodeCodePointCount), + const int additionalCodePointCount = std::min( + static_cast<int>(mergedNodeCodePointCount), MAX_WORD_LENGTH - mOutputtedCodePointCount); memmove(&mCodePointsBuf[mOutputtedCodePointCount], mergedNodeCodePoints, additionalCodePointCount * sizeof(mCodePointsBuf[0])); diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h index e7108d976..7868f7853 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h @@ -17,6 +17,7 @@ #ifndef LATINIME_DIC_NODE_STATE_PREVWORD_H #define LATINIME_DIC_NODE_STATE_PREVWORD_H +#include <algorithm> #include <cstring> // for memset() and memmove() #include <stdint.h> @@ -69,7 +70,7 @@ class DicNodeStatePrevWord { const int prevWordNodePos, const int *const src0, const int16_t length0, const int *const src1, const int16_t length1, const int prevWordSecondWordFirstInputIndex, const int lastInputIndex) { - mPrevWordCount = min(prevWordCount, static_cast<int16_t>(MAX_RESULTS)); + mPrevWordCount = std::min(prevWordCount, static_cast<int16_t>(MAX_RESULTS)); mPrevWordProbability = prevWordProbability; mPrevWordPtNodePos = prevWordNodePos; int twoWordsLen = diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h index 11c201e52..18b7d736a 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h @@ -17,6 +17,7 @@ #ifndef LATINIME_DIC_NODE_STATE_SCORING_H #define LATINIME_DIC_NODE_STATE_SCORING_H +#include <algorithm> #include <stdint.h> #include "defines.h" @@ -199,7 +200,7 @@ class DicNodeStateScoring { mNormalizedCompoundDistance = mSpatialDistance + mLanguageDistance; } else { mNormalizedCompoundDistance = (mSpatialDistance + mLanguageDistance) - / static_cast<float>(max(1, totalInputIndex)); + / static_cast<float>(std::max(1, totalInputIndex)); } } }; diff --git a/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp b/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp index d0b96b0fe..0859df423 100644 --- a/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp @@ -14,12 +14,13 @@ * limitations under the License. */ -#include <cstring> - #define LOG_TAG "LatinIME: bigram_dictionary.cpp" #include "bigram_dictionary.h" +#include <algorithm> +#include <cstring> + #include "defines.h" #include "suggest/core/dictionary/binary_dictionary_bigrams_iterator.h" #include "suggest/core/dictionary/dictionary.h" @@ -142,7 +143,7 @@ int BigramDictionary::getPredictions(const int *prevWord, const int prevWordLeng outBigramCodePoints, outputTypes); ++bigramCount; } - return min(bigramCount, MAX_RESULTS); + return std::min(bigramCount, MAX_RESULTS); } // Returns a pointer to the start of the bigram list. diff --git a/native/jni/src/suggest/core/layout/proximity_info.cpp b/native/jni/src/suggest/core/layout/proximity_info.cpp index ee8e59ef9..8b3ae4db8 100644 --- a/native/jni/src/suggest/core/layout/proximity_info.cpp +++ b/native/jni/src/suggest/core/layout/proximity_info.cpp @@ -18,6 +18,7 @@ #include "suggest/core/layout/proximity_info.h" +#include <algorithm> #include <cstring> #include <cmath> @@ -63,7 +64,7 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, static_cast<float>(mostCommonKeyWidth))), CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth), CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight), - KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), + KEY_COUNT(std::min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), KEYBOARD_WIDTH(keyboardWidth), KEYBOARD_HEIGHT(keyboardHeight), KEYBOARD_HYPOTENUSE(hypotf(KEYBOARD_WIDTH, KEYBOARD_HEIGHT)), HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates diff --git a/native/jni/src/suggest/core/layout/proximity_info_state.cpp b/native/jni/src/suggest/core/layout/proximity_info_state.cpp index 40c3448ef..2919904e5 100644 --- a/native/jni/src/suggest/core/layout/proximity_info_state.cpp +++ b/native/jni/src/suggest/core/layout/proximity_info_state.cpp @@ -18,6 +18,7 @@ #include "suggest/core/layout/proximity_info_state.h" +#include <algorithm> #include <cstring> // for memset() and memmove() #include <sstream> // for debug prints #include <vector> @@ -171,7 +172,7 @@ float ProximityInfoState::getPointToKeyLength( const int keyId = mProximityInfo->getKeyIndexOf(codePoint); if (keyId != NOT_AN_INDEX) { const int index = inputIndex * mProximityInfo->getKeyCount() + keyId; - return min(mSampledNormalizedSquaredLengthCache[index], mMaxPointToKeyLength); + return std::min(mSampledNormalizedSquaredLengthCache[index], mMaxPointToKeyLength); } if (CharUtils::isIntentionalOmissionCodePoint(codePoint)) { return 0.0f; diff --git a/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp b/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp index bc4ca8e9e..867f59843 100644 --- a/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp +++ b/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp @@ -16,6 +16,7 @@ #include "suggest/core/layout/proximity_info_state_utils.h" +#include <algorithm> #include <cmath> #include <cstring> // for memset() #include <sstream> // for debug prints @@ -240,7 +241,7 @@ namespace latinime { // Calculate velocity by using distances and durations of // ProximityInfoParams::NUM_POINTS_FOR_SPEED_CALCULATION points for both forward and // backward. - const int forwardNumPoints = min(inputSize - 1, + const int forwardNumPoints = std::min(inputSize - 1, index + ProximityInfoParams::NUM_POINTS_FOR_SPEED_CALCULATION); for (int j = index; j < forwardNumPoints; ++j) { if (i < sampledInputSize - 1 && j >= (*sampledInputIndice)[i + 1]) { @@ -250,7 +251,7 @@ namespace latinime { xCoordinates[j + 1], yCoordinates[j + 1]); duration += times[j + 1] - times[j]; } - const int backwardNumPoints = max(0, + const int backwardNumPoints = std::max(0, index - ProximityInfoParams::NUM_POINTS_FOR_SPEED_CALCULATION); for (int j = index - 1; j >= backwardNumPoints; --j) { if (i > 0 && j < (*sampledInputIndice)[i - 1]) { @@ -272,7 +273,7 @@ namespace latinime { // Direction calculation. sampledDirections->resize(sampledInputSize - 1); - for (int i = max(0, lastSavedInputSize - 1); i < sampledInputSize - 1; ++i) { + for (int i = std::max(0, lastSavedInputSize - 1); i < sampledInputSize - 1; ++i) { (*sampledDirections)[i] = getDirection(sampledInputXs, sampledInputYs, i, i + 1); } return averageSpeed; @@ -609,7 +610,7 @@ namespace latinime { const int inputIndex, const int keyId) { if (keyId != NOT_AN_INDEX) { const int index = inputIndex * keyCount + keyId; - return min((*sampledNormalizedSquaredLengthCache)[index], maxPointToKeyLength); + return std::min((*sampledNormalizedSquaredLengthCache)[index], maxPointToKeyLength); } // If the char is not a key on the keyboard then return the max length. return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); @@ -650,13 +651,13 @@ namespace latinime { } if (i == 0) { - skipProbability *= min(1.0f, + skipProbability *= std::min(1.0f, nearestKeyDistance * ProximityInfoParams::NEAREST_DISTANCE_WEIGHT + ProximityInfoParams::NEAREST_DISTANCE_BIAS); // Promote the first point skipProbability *= ProximityInfoParams::SKIP_FIRST_POINT_PROBABILITY; } else if (i == sampledInputSize - 1) { - skipProbability *= min(1.0f, + skipProbability *= std::min(1.0f, nearestKeyDistance * ProximityInfoParams::NEAREST_DISTANCE_WEIGHT_FOR_LAST + ProximityInfoParams::NEAREST_DISTANCE_BIAS_FOR_LAST); // Promote the last point @@ -667,17 +668,17 @@ namespace latinime { && speedRate < (*sampledSpeedRates)[i + 1] - ProximityInfoParams::SPEED_MARGIN) { if (currentAngle < ProximityInfoParams::CORNER_ANGLE_THRESHOLD) { - skipProbability *= min(1.0f, speedRate + skipProbability *= std::min(1.0f, speedRate * ProximityInfoParams::SLOW_STRAIGHT_WEIGHT_FOR_SKIP_PROBABILITY); } else { // If the angle is small enough, we promote this point more. (e.g. pit vs put) - skipProbability *= min(1.0f, + skipProbability *= std::min(1.0f, speedRate * ProximityInfoParams::SPEED_WEIGHT_FOR_SKIP_PROBABILITY + ProximityInfoParams::MIN_SPEED_RATE_FOR_SKIP_PROBABILITY); } } - skipProbability *= min(1.0f, + skipProbability *= std::min(1.0f, speedRate * nearestKeyDistance * ProximityInfoParams::NEAREST_DISTANCE_WEIGHT + ProximityInfoParams::NEAREST_DISTANCE_BIAS); @@ -707,10 +708,10 @@ namespace latinime { // (1.0f - skipProbability). const float inputCharProbability = 1.0f - skipProbability; - const float speedxAngleRate = min(speedRate * currentAngle / M_PI_F + const float speedxAngleRate = std::min(speedRate * currentAngle / M_PI_F * ProximityInfoParams::SPEEDxANGLE_WEIGHT_FOR_STANDARD_DEVIATION, ProximityInfoParams::MAX_SPEEDxANGLE_RATE_FOR_STANDARD_DEVIATION); - const float speedxNearestKeyDistanceRate = min(speedRate * nearestKeyDistance + const float speedxNearestKeyDistanceRate = std::min(speedRate * nearestKeyDistance * ProximityInfoParams::SPEEDxNEAREST_WEIGHT_FOR_STANDARD_DEVIATION, ProximityInfoParams::MAX_SPEEDxNEAREST_RATE_FOR_STANDARD_DEVIATION); const float sigma = speedxAngleRate + speedxNearestKeyDistanceRate @@ -827,7 +828,7 @@ namespace latinime { // Decrease key probabilities of points which don't have the highest probability of that key // among nearby points. Probabilities of the first point and the last point are not suppressed. - for (int i = max(start, 1); i < sampledInputSize; ++i) { + for (int i = std::max(start, 1); i < sampledInputSize; ++i) { for (int j = i + 1; j < sampledInputSize; ++j) { if (!suppressCharProbabilities( mostCommonKeyWidth, sampledInputSize, sampledLengthCache, i, j, @@ -835,7 +836,7 @@ namespace latinime { break; } } - for (int j = i - 1; j >= max(start, 0); --j) { + for (int j = i - 1; j >= std::max(start, 0); --j) { if (!suppressCharProbabilities( mostCommonKeyWidth, sampledInputSize, sampledLengthCache, i, j, charProbabilities)) { @@ -878,7 +879,7 @@ namespace latinime { if (i >= lastSavedInputSize) { (*sampledSearchKeySets)[i].reset(); } - for (int j = max(i, lastSavedInputSize); j < sampledInputSize; ++j) { + for (int j = std::max(i, lastSavedInputSize); j < sampledInputSize; ++j) { // TODO: Investigate if this is required. This may not fail. if ((*sampledLengthCache)[j] - (*sampledLengthCache)[i] >= readForwordLength) { break; @@ -929,7 +930,7 @@ namespace latinime { (*charProbabilities)[index0][NOT_AN_INDEX] += suppression; // Add the probability of the same key nearby index1 - const float probabilityGain = min(suppression + const float probabilityGain = std::min(suppression * ProximityInfoParams::SUPPRESSION_WEIGHT_FOR_PROBABILITY_GAIN, (*charProbabilities)[index1][NOT_AN_INDEX] * ProximityInfoParams::SKIP_PROBABALITY_WEIGHT_FOR_PROBABILITY_GAIN); diff --git a/native/jni/src/suggest/core/layout/proximity_info_utils.h b/native/jni/src/suggest/core/layout/proximity_info_utils.h index bc8d5bc1d..6d2c11b09 100644 --- a/native/jni/src/suggest/core/layout/proximity_info_utils.h +++ b/native/jni/src/suggest/core/layout/proximity_info_utils.h @@ -164,12 +164,15 @@ class ProximityInfoUtils { 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) { - if (x == NOT_A_COORDINATE || y == NOT_A_COORDINATE) { - return; - } const int mostCommonKeyWidthSquare = mostCommonKeyWidth * mostCommonKeyWidth; int insertPos = 0; proximities[insertPos++] = primaryKey; + if (x == NOT_A_COORDINATE || y == NOT_A_COORDINATE) { + for (int i = insertPos; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { + proximities[i] = NOT_A_CODE_POINT; + } + return; + } const int startIndex = getStartIndexFromCoordinates(x, y, cellHeight, cellWidth, gridWidth); if (startIndex >= 0) { for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { diff --git a/native/jni/src/suggest/core/layout/touch_position_correction_utils.h b/native/jni/src/suggest/core/layout/touch_position_correction_utils.h index 9130e87d3..14074c13d 100644 --- a/native/jni/src/suggest/core/layout/touch_position_correction_utils.h +++ b/native/jni/src/suggest/core/layout/touch_position_correction_utils.h @@ -17,6 +17,8 @@ #ifndef LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H #define LATINIME_TOUCH_POSITION_CORRECTION_UTILS_H +#include <algorithm> + #include "defines.h" #include "suggest/core/layout/proximity_info_params.h" @@ -34,7 +36,7 @@ class TouchPositionCorrectionUtils { static const float R2 = 1.0f; const float x = normalizedSquaredDistance; if (!isTouchPositionCorrectionEnabled) { - return min(C, x); + return std::min(C, x); } // factor is a piecewise linear function like: diff --git a/native/jni/src/suggest/core/dictionary/suggestions_output_utils.cpp b/native/jni/src/suggest/core/result/suggestions_output_utils.cpp index 07c2e6ea9..19912f2ac 100644 --- a/native/jni/src/suggest/core/dictionary/suggestions_output_utils.cpp +++ b/native/jni/src/suggest/core/result/suggestions_output_utils.cpp @@ -14,7 +14,9 @@ * limitations under the License. */ -#include "suggest/core/dictionary/suggestions_output_utils.h" +#include "suggest/core/result/suggestions_output_utils.h" + +#include <algorithm> #include "suggest/core/dicnode/dic_node.h" #include "suggest/core/dicnode/dic_node_utils.h" @@ -36,7 +38,7 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16; #if DEBUG_EVALUATE_MOST_PROBABLE_STRING const int terminalSize = 0; #else - const int terminalSize = min(MAX_RESULTS, + const int terminalSize = std::min(MAX_RESULTS, static_cast<int>(traverseSession->getDicTraverseCache()->terminalSize())); #endif DicNode terminals[MAX_RESULTS]; // Avoiding non-POD variable length array @@ -245,12 +247,12 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16; // shortcut entry's score == its base entry's score - 1 shortcutScore = finalScore; // Protection against int underflow - shortcutScore = max(S_INT_MIN + 1, shortcutScore) - 1; + shortcutScore = std::max(S_INT_MIN + 1, shortcutScore) - 1; kind = Dictionary::KIND_SHORTCUT; } outputTypes[outputWordIndex] = kind; outputScores[outputWordIndex] = shortcutScore; - outputScores[outputWordIndex] = max(S_INT_MIN + 1, shortcutScore) - 1; + outputScores[outputWordIndex] = std::max(S_INT_MIN + 1, shortcutScore) - 1; const int startIndex2 = outputWordIndex * MAX_WORD_LENGTH; DicNodeUtils::appendTwoWords(0, 0, shortcutTarget, shortcutTargetStringLength, &outputCodePoints[startIndex2]); diff --git a/native/jni/src/suggest/core/dictionary/suggestions_output_utils.h b/native/jni/src/suggest/core/result/suggestions_output_utils.h index d456a545f..d456a545f 100644 --- a/native/jni/src/suggest/core/dictionary/suggestions_output_utils.h +++ b/native/jni/src/suggest/core/result/suggestions_output_utils.h diff --git a/native/jni/src/suggest/core/suggest.cpp b/native/jni/src/suggest/core/suggest.cpp index 56acc2dc1..c3b670337 100644 --- a/native/jni/src/suggest/core/suggest.cpp +++ b/native/jni/src/suggest/core/suggest.cpp @@ -21,11 +21,11 @@ #include "suggest/core/dicnode/dic_node_vector.h" #include "suggest/core/dictionary/dictionary.h" #include "suggest/core/dictionary/digraph_utils.h" -#include "suggest/core/dictionary/suggestions_output_utils.h" #include "suggest/core/layout/proximity_info.h" #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h" #include "suggest/core/policy/traversal.h" #include "suggest/core/policy/weighting.h" +#include "suggest/core/result/suggestions_output_utils.h" #include "suggest/core/session/dic_traverse_session.h" namespace latinime { diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp index 7c7b05ca8..ecc9fdab1 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp @@ -16,6 +16,8 @@ #include "suggest/policyimpl/dictionary/header/header_policy.h" +#include <algorithm> + namespace latinime { // Note that these are corresponding definitions in Java side in DictionaryHeader. @@ -72,7 +74,7 @@ void HeaderPolicy::readHeaderValueOrQuestionMark(const char *const key, int *out outValue[1] = '\0'; return; } - const int terminalIndex = min(static_cast<int>(it->second.size()), outValueSize - 1); + const int terminalIndex = std::min(static_cast<int>(it->second.size()), outValueSize - 1); for (int i = 0; i < terminalIndex; ++i) { outValue[i] = it->second[i]; } diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp index 35e05d77a..bac4d4eba 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp @@ -16,6 +16,7 @@ #include "suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h" +#include <algorithm> #include <cmath> #include <stdlib.h> @@ -72,7 +73,7 @@ const ForgettingCurveUtils::ProbabilityTable ForgettingCurveUtils::sProbabilityT headerPolicy->getForgettingCurveDurationToLevelDown()); return sProbabilityTable.getProbability( headerPolicy->getForgettingCurveProbabilityValuesTableId(), historicalInfo->getLevel(), - min(max(elapsedTimeStepCount, 0), MAX_ELAPSED_TIME_STEP_COUNT)); + std::min(std::max(elapsedTimeStepCount, 0), MAX_ELAPSED_TIME_STEP_COUNT)); } /* static */ int ForgettingCurveUtils::getProbability(const int unigramProbability, @@ -80,11 +81,11 @@ const ForgettingCurveUtils::ProbabilityTable ForgettingCurveUtils::sProbabilityT if (unigramProbability == NOT_A_PROBABILITY) { return NOT_A_PROBABILITY; } else if (bigramProbability == NOT_A_PROBABILITY) { - return min(backoff(unigramProbability), MAX_PROBABILITY); + return std::min(backoff(unigramProbability), MAX_PROBABILITY); } else { // TODO: Investigate better way to handle bigram probability. - return min(max(unigramProbability, bigramProbability + MULTIPLIER_TWO_IN_PROBABILITY_SCALE), - MAX_PROBABILITY); + return std::min(std::max(unigramProbability, + bigramProbability + MULTIPLIER_TWO_IN_PROBABILITY_SCALE), MAX_PROBABILITY); } } @@ -183,7 +184,7 @@ ForgettingCurveUtils::ProbabilityTable::ProbabilityTable() : mTables() { -1.0f * static_cast<float>(timeStepCount) / static_cast<float>(MAX_ELAPSED_TIME_STEP_COUNT + 1)); mTables[tableId][level][timeStepCount] = - min(max(static_cast<int>(probability), 1), MAX_PROBABILITY); + std::min(std::max(static_cast<int>(probability), 1), MAX_PROBABILITY); } } } diff --git a/native/jni/src/suggest/policyimpl/utils/edit_distance.h b/native/jni/src/suggest/policyimpl/utils/edit_distance.h index 0871c37ce..4cfd0b3f3 100644 --- a/native/jni/src/suggest/policyimpl/utils/edit_distance.h +++ b/native/jni/src/suggest/policyimpl/utils/edit_distance.h @@ -17,6 +17,8 @@ #ifndef LATINIME_EDIT_DISTANCE_H #define LATINIME_EDIT_DISTANCE_H +#include <algorithm> + #include "defines.h" #include "suggest/policyimpl/utils/edit_distance_policy.h" @@ -38,13 +40,13 @@ class EditDistance { for (int i = 0; i < beforeLength; ++i) { for (int j = 0; j < afterLength; ++j) { - dp[(afterLength + 1) * (i + 1) + (j + 1)] = min( + dp[(afterLength + 1) * (i + 1) + (j + 1)] = std::min( dp[(afterLength + 1) * i + (j + 1)] + policy->getInsertionCost(i, j), - min(dp[(afterLength + 1) * (i + 1) + j] + policy->getDeletionCost(i, j), - dp[(afterLength + 1) * i + j] - + policy->getSubstitutionCost(i, j))); + std::min( + dp[(afterLength + 1) * (i + 1) + j] + policy->getDeletionCost(i, j), + dp[(afterLength + 1) * i + j] + policy->getSubstitutionCost(i, j))); if (policy->allowTransposition(i, j)) { - dp[(afterLength + 1) * (i + 1) + (j + 1)] = min( + dp[(afterLength + 1) * (i + 1) + (j + 1)] = std::min( dp[(afterLength + 1) * (i + 1) + (j + 1)], dp[(afterLength + 1) * (i - 1) + (j - 1)] + policy->getTranspositionCost(i, j)); diff --git a/native/jni/src/utils/autocorrection_threshold_utils.cpp b/native/jni/src/utils/autocorrection_threshold_utils.cpp index 1f8ee0814..349786a27 100644 --- a/native/jni/src/utils/autocorrection_threshold_utils.cpp +++ b/native/jni/src/utils/autocorrection_threshold_utils.cpp @@ -16,6 +16,7 @@ #include "utils/autocorrection_threshold_utils.h" +#include <algorithm> #include <cmath> #include "defines.h" @@ -99,7 +100,7 @@ const int AutocorrectionThresholdUtils::FULL_WORD_MULTIPLIER = 2; const float maxScore = score >= S_INT_MAX ? static_cast<float>(S_INT_MAX) : static_cast<float>(MAX_INITIAL_SCORE) * powf(static_cast<float>(TYPED_LETTER_MULTIPLIER), - static_cast<float>(min(beforeLength, afterLength - spaceCount))) + static_cast<float>(std::min(beforeLength, afterLength - spaceCount))) * static_cast<float>(FULL_WORD_MULTIPLIER); return (static_cast<float>(score) / maxScore) * weight; diff --git a/native/jni/src/utils/hash_map_compat.h b/native/jni/src/utils/hash_map_compat.h index a1e982bc4..7bf35a660 100644 --- a/native/jni/src/utils/hash_map_compat.h +++ b/native/jni/src/utils/hash_map_compat.h @@ -17,18 +17,12 @@ #ifndef LATINIME_HASH_MAP_COMPAT_H #define LATINIME_HASH_MAP_COMPAT_H -// TODO: Use std::unordered_map that has been standardized in C++11 +#include <unordered_map> -#ifdef __APPLE__ -#include <ext/hash_map> -#else // __APPLE__ -#include <hash_map> -#endif // __APPLE__ +#define hash_map_compat std::unordered_map -#ifdef __SGI_STL_PORT -#define hash_map_compat stlport::hash_map -#else // __SGI_STL_PORT -#define hash_map_compat __gnu_cxx::hash_map -#endif // __SGI_STL_PORT +#if 0 // TODO: Use this instead of the above macro. +template <typename TKey, typename TValue> using hash_map_compat = std::unordered_map<TKey, TValue>; +#endif #endif // LATINIME_HASH_MAP_COMPAT_H |