am 8ca9be17: s/hash_map_compat/unordered_map/

* commit '8ca9be17db2f1845c7c7a3b584507cf60c9ca53d':
  s/hash_map_compat/unordered_map/
main
Ken Wakasa 2014-04-11 09:16:25 +00:00 committed by Android Git Automerger
commit 0dc6ecc682
13 changed files with 41 additions and 66 deletions

View File

@ -17,6 +17,7 @@
#include "suggest/core/dictionary/multi_bigram_map.h"
#include <cstddef>
#include <unordered_map>
namespace latinime {
@ -35,7 +36,7 @@ const int MultiBigramMap::BigramMap::DEFAULT_HASH_MAP_SIZE_FOR_EACH_BIGRAM_MAP =
int MultiBigramMap::getBigramProbability(
const DictionaryStructureWithBufferPolicy *const structurePolicy,
const int wordPosition, const int nextWordPosition, const int unigramProbability) {
hash_map_compat<int, BigramMap>::const_iterator mapPosition =
std::unordered_map<int, BigramMap>::const_iterator mapPosition =
mBigramMaps.find(wordPosition);
if (mapPosition != mBigramMaps.end()) {
return mapPosition->second.getBigramProbability(structurePolicy, nextWordPosition,
@ -70,7 +71,7 @@ int MultiBigramMap::BigramMap::getBigramProbability(
const int nextWordPosition, const int unigramProbability) const {
int bigramProbability = NOT_A_PROBABILITY;
if (mBloomFilter.isInFilter(nextWordPosition)) {
const hash_map_compat<int, int>::const_iterator bigramProbabilityIt =
const std::unordered_map<int, int>::const_iterator bigramProbabilityIt =
mBigramMap.find(nextWordPosition);
if (bigramProbabilityIt != mBigramMap.end()) {
bigramProbability = bigramProbabilityIt->second;

View File

@ -18,12 +18,12 @@
#define LATINIME_MULTI_BIGRAM_MAP_H
#include <cstddef>
#include <unordered_map>
#include "defines.h"
#include "suggest/core/dictionary/binary_dictionary_bigrams_iterator.h"
#include "suggest/core/dictionary/bloom_filter.h"
#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
#include "utils/hash_map_compat.h"
namespace latinime {
@ -63,7 +63,7 @@ class MultiBigramMap {
// NOTE: The BigramMap class doesn't use DISALLOW_COPY_AND_ASSIGN() because its default
// copy constructor is needed for use in hash_map.
static const int DEFAULT_HASH_MAP_SIZE_FOR_EACH_BIGRAM_MAP;
hash_map_compat<int, int> mBigramMap;
std::unordered_map<int, int> mBigramMap;
BloomFilter mBloomFilter;
};
@ -75,7 +75,7 @@ class MultiBigramMap {
const int nextWordPosition, const int unigramProbability);
static const size_t MAX_CACHED_PREV_WORDS_IN_BIGRAM_MAP;
hash_map_compat<int, BigramMap> mBigramMaps;
std::unordered_map<int, BigramMap> mBigramMaps;
};
} // namespace latinime
#endif // LATINIME_MULTI_BIGRAM_MAP_H

View File

@ -17,10 +17,11 @@
#ifndef LATINIME_PROXIMITY_INFO_H
#define LATINIME_PROXIMITY_INFO_H
#include <unordered_map>
#include "defines.h"
#include "jni.h"
#include "suggest/core/layout/proximity_info_utils.h"
#include "utils/hash_map_compat.h"
namespace latinime {
@ -114,7 +115,7 @@ class ProximityInfo {
// Sweet spots for geometric input. Note that we have extra sweet spots only for Y coordinates.
float mSweetSpotCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
hash_map_compat<int, int> mLowerCodePointToKeyMap;
std::unordered_map<int, int> mLowerCodePointToKeyMap;
int mKeyIndexToOriginalCodePoint[MAX_KEY_COUNT_IN_A_KEYBOARD];
int mKeyIndexToLowerCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];

View File

@ -21,6 +21,7 @@
#include <algorithm>
#include <cstring> // for memset() and memmove()
#include <sstream> // for debug prints
#include <unordered_map>
#include <vector>
#include "defines.h"
@ -296,7 +297,7 @@ bool ProximityInfoState::hasSpaceProximity(const int index) const {
// Returns a probability of mapping index to keyIndex.
float ProximityInfoState::getProbability(const int index, const int keyIndex) const {
ASSERT(0 <= index && index < mSampledInputSize);
hash_map_compat<int, float>::const_iterator it = mCharProbabilities[index].find(keyIndex);
std::unordered_map<int, float>::const_iterator it = mCharProbabilities[index].find(keyIndex);
if (it != mCharProbabilities[index].end()) {
return it->second;
}

View File

@ -18,12 +18,12 @@
#define LATINIME_PROXIMITY_INFO_STATE_H
#include <cstring> // for memset()
#include <unordered_map>
#include <vector>
#include "defines.h"
#include "suggest/core/layout/proximity_info_params.h"
#include "suggest/core/layout/proximity_info_state_utils.h"
#include "utils/hash_map_compat.h"
namespace latinime {
@ -215,7 +215,7 @@ class ProximityInfoState {
std::vector<float> mSpeedRates;
std::vector<float> mDirections;
// probabilities of skipping or mapping to a key for each point.
std::vector<hash_map_compat<int, float> > mCharProbabilities;
std::vector<std::unordered_map<int, float> > mCharProbabilities;
// The vector for the key code set which holds nearby keys of some trailing sampled input points
// for each sampled input point. These nearby keys contain the next characters which can be in
// the dictionary. Specifically, currently we are looking for keys nearby trailing sampled

View File

@ -20,6 +20,7 @@
#include <cmath>
#include <cstring> // for memset()
#include <sstream> // for debug prints
#include <unordered_map>
#include <vector>
#include "defines.h"
@ -620,7 +621,7 @@ namespace latinime {
const std::vector<int> *const sampledLengthCache,
const std::vector<float> *const sampledNormalizedSquaredLengthCache,
const ProximityInfo *const proximityInfo,
std::vector<hash_map_compat<int, float> > *charProbabilities) {
std::vector<std::unordered_map<int, float> > *charProbabilities) {
charProbabilities->resize(sampledInputSize);
// Calculates probabilities of using a point as a correlated point with the character
// for each point.
@ -762,7 +763,7 @@ namespace latinime {
sstream << "Speed: "<< (*sampledSpeedRates)[i] << ", ";
sstream << "Angle: "<< getPointAngle(sampledInputXs, sampledInputYs, i) << ", \n";
for (hash_map_compat<int, float>::iterator it = (*charProbabilities)[i].begin();
for (std::unordered_map<int, float>::iterator it = (*charProbabilities)[i].begin();
it != (*charProbabilities)[i].end(); ++it) {
if (it->first == NOT_AN_INDEX) {
sstream << it->first
@ -804,7 +805,7 @@ namespace latinime {
// Converting from raw probabilities to log probabilities to calculate spatial distance.
for (int i = start; i < sampledInputSize; ++i) {
for (int j = 0; j < keyCount; ++j) {
hash_map_compat<int, float>::iterator it = (*charProbabilities)[i].find(j);
std::unordered_map<int, float>::iterator it = (*charProbabilities)[i].find(j);
if (it == (*charProbabilities)[i].end()){
continue;
} else if(it->second < ProximityInfoParams::MIN_PROBABILITY) {
@ -821,7 +822,7 @@ namespace latinime {
/* static */ void ProximityInfoStateUtils::updateSampledSearchKeySets(
const ProximityInfo *const proximityInfo, const int sampledInputSize,
const int lastSavedInputSize, const std::vector<int> *const sampledLengthCache,
const std::vector<hash_map_compat<int, float> > *const charProbabilities,
const std::vector<std::unordered_map<int, float> > *const charProbabilities,
std::vector<NearKeycodesSet> *sampledSearchKeySets,
std::vector<std::vector<int> > *sampledSearchKeyVectors) {
sampledSearchKeySets->resize(sampledInputSize);
@ -867,7 +868,7 @@ namespace latinime {
/* static */ bool ProximityInfoStateUtils::suppressCharProbabilities(const int mostCommonKeyWidth,
const int sampledInputSize, const std::vector<int> *const lengthCache,
const int index0, const int index1,
std::vector<hash_map_compat<int, float> > *charProbabilities) {
std::vector<std::unordered_map<int, float> > *charProbabilities) {
ASSERT(0 <= index0 && index0 < sampledInputSize);
ASSERT(0 <= index1 && index1 < sampledInputSize);
const float keyWidthFloat = static_cast<float>(mostCommonKeyWidth);
@ -878,9 +879,9 @@ namespace latinime {
const float suppressionRate = ProximityInfoParams::MIN_SUPPRESSION_RATE
+ diff / keyWidthFloat / ProximityInfoParams::SUPPRESSION_LENGTH_WEIGHT
* ProximityInfoParams::SUPPRESSION_WEIGHT;
for (hash_map_compat<int, float>::iterator it = (*charProbabilities)[index0].begin();
for (std::unordered_map<int, float>::iterator it = (*charProbabilities)[index0].begin();
it != (*charProbabilities)[index0].end(); ++it) {
hash_map_compat<int, float>::iterator it2 = (*charProbabilities)[index1].find(it->first);
std::unordered_map<int, float>::iterator it2 = (*charProbabilities)[index1].find(it->first);
if (it2 != (*charProbabilities)[index1].end() && it->second < it2->second) {
const float newProbability = it->second * suppressionRate;
const float suppression = it->second - newProbability;
@ -932,7 +933,7 @@ namespace latinime {
// returns probability of generating the word.
/* static */ float ProximityInfoStateUtils::getMostProbableString(
const ProximityInfo *const proximityInfo, const int sampledInputSize,
const std::vector<hash_map_compat<int, float> > *const charProbabilities,
const std::vector<std::unordered_map<int, float> > *const charProbabilities,
int *const codePointBuf) {
ASSERT(sampledInputSize >= 0);
memset(codePointBuf, 0, sizeof(codePointBuf[0]) * MAX_WORD_LENGTH);
@ -942,7 +943,7 @@ namespace latinime {
for (int i = 0; i < sampledInputSize && index < MAX_WORD_LENGTH - 1; ++i) {
float minLogProbability = static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
int character = NOT_AN_INDEX;
for (hash_map_compat<int, float>::const_iterator it = (*charProbabilities)[i].begin();
for (std::unordered_map<int, float>::const_iterator it = (*charProbabilities)[i].begin();
it != (*charProbabilities)[i].end(); ++it) {
const float logProbability = (it->first != NOT_AN_INDEX)
? it->second + ProximityInfoParams::DEMOTION_LOG_PROBABILITY : it->second;

View File

@ -18,10 +18,10 @@
#define LATINIME_PROXIMITY_INFO_STATE_UTILS_H
#include <bitset>
#include <unordered_map>
#include <vector>
#include "defines.h"
#include "utils/hash_map_compat.h"
namespace latinime {
class ProximityInfo;
@ -29,7 +29,7 @@ class ProximityInfoParams;
class ProximityInfoStateUtils {
public:
typedef hash_map_compat<int, float> NearKeysDistanceMap;
typedef std::unordered_map<int, float> NearKeysDistanceMap;
typedef std::bitset<MAX_KEY_COUNT_IN_A_KEYBOARD> NearKeycodesSet;
static int trimLastTwoTouchPoints(std::vector<int> *sampledInputXs,
@ -72,11 +72,11 @@ class ProximityInfoStateUtils {
const std::vector<int> *const sampledLengthCache,
const std::vector<float> *const sampledNormalizedSquaredLengthCache,
const ProximityInfo *const proximityInfo,
std::vector<hash_map_compat<int, float> > *charProbabilities);
std::vector<std::unordered_map<int, float> > *charProbabilities);
static void updateSampledSearchKeySets(const ProximityInfo *const proximityInfo,
const int sampledInputSize, const int lastSavedInputSize,
const std::vector<int> *const sampledLengthCache,
const std::vector<hash_map_compat<int, float> > *const charProbabilities,
const std::vector<std::unordered_map<int, float> > *const charProbabilities,
std::vector<NearKeycodesSet> *sampledSearchKeySets,
std::vector<std::vector<int> > *sampledSearchKeyVectors);
static float getPointToKeyByIdLength(const float maxPointToKeyLength,
@ -105,7 +105,7 @@ class ProximityInfoStateUtils {
// TODO: Move to most_probable_string_utils.h
static float getMostProbableString(const ProximityInfo *const proximityInfo,
const int sampledInputSize,
const std::vector<hash_map_compat<int, float> > *const charProbabilities,
const std::vector<std::unordered_map<int, float> > *const charProbabilities,
int *const codePointBuf);
private:
@ -147,7 +147,7 @@ class ProximityInfoStateUtils {
const int index2);
static bool suppressCharProbabilities(const int mostCommonKeyWidth,
const int sampledInputSize, const std::vector<int> *const lengthCache, const int index0,
const int index1, std::vector<hash_map_compat<int, float> > *charProbabilities);
const int index1, std::vector<std::unordered_map<int, float> > *charProbabilities);
static float calculateSquaredDistanceFromSweetSpotCenter(
const ProximityInfo *const proximityInfo, const std::vector<int> *const sampledInputXs,
const std::vector<int> *const sampledInputYs, const int keyIndex,

View File

@ -18,18 +18,18 @@
#define LATINIME_PROXIMITY_INFO_UTILS_H
#include <cmath>
#include <unordered_map>
#include "defines.h"
#include "suggest/core/layout/additional_proximity_chars.h"
#include "suggest/core/layout/geometry_utils.h"
#include "utils/char_utils.h"
#include "utils/hash_map_compat.h"
namespace latinime {
class ProximityInfoUtils {
public:
static AK_FORCE_INLINE int getKeyIndexOf(const int keyCount, const int c,
const hash_map_compat<int, int> *const codeToKeyMap) {
const std::unordered_map<int, int> *const codeToKeyMap) {
if (keyCount == 0) {
// We do not have the coordinate data
return NOT_AN_INDEX;
@ -38,7 +38,7 @@ class ProximityInfoUtils {
return NOT_AN_INDEX;
}
const int lowerCode = CharUtils::toLowerCase(c);
hash_map_compat<int, int>::const_iterator mapPos = codeToKeyMap->find(lowerCode);
std::unordered_map<int, int>::const_iterator mapPos = codeToKeyMap->find(lowerCode);
if (mapPos != codeToKeyMap->end()) {
return mapPos->second;
}
@ -52,7 +52,7 @@ class ProximityInfoUtils {
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) {
const std::unordered_map<int, int> *const codeToKeyMap, int *inputProximities) {
// Initialize
// - mInputCodes
// - mNormalizedSquaredDistances
@ -144,7 +144,7 @@ class ProximityInfoUtils {
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 std::unordered_map<int, int> *const codeToKeyMap, int *proximities) {
const int mostCommonKeyWidthSquare = mostCommonKeyWidth * mostCommonKeyWidth;
int insertPos = 0;
proximities[insertPos++] = primaryKey;

View File

@ -23,7 +23,6 @@
#include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
#include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_writer.h"
#include "suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h"
#include "utils/hash_map_compat.h"
namespace latinime {

View File

@ -19,7 +19,6 @@
#include "defines.h"
#include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h"
#include "utils/hash_map_compat.h"
namespace latinime {

View File

@ -17,18 +17,18 @@
#ifndef LATINIME_PT_NODE_WRITER_H
#define LATINIME_PT_NODE_WRITER_H
#include "defines.h"
#include <unordered_map>
#include "defines.h"
#include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h"
#include "utils/hash_map_compat.h"
namespace latinime {
// Interface class used to write PtNode information.
class PtNodeWriter {
public:
typedef hash_map_compat<int, int> PtNodeArrayPositionRelocationMap;
typedef hash_map_compat<int, int> PtNodePositionRelocationMap;
typedef std::unordered_map<int, int> PtNodeArrayPositionRelocationMap;
typedef std::unordered_map<int, int> PtNodePositionRelocationMap;
struct DictPositionRelocationMap {
public:
DictPositionRelocationMap()

View File

@ -17,16 +17,17 @@
#ifndef LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H
#define LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H
#include <unordered_map>
#include "defines.h"
#include "suggest/policyimpl/dictionary/structure/v4/content/single_dict_content.h"
#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
#include "utils/hash_map_compat.h"
namespace latinime {
class TerminalPositionLookupTable : public SingleDictContent {
public:
typedef hash_map_compat<int, int> TerminalIdMap;
typedef std::unordered_map<int, int> TerminalIdMap;
TerminalPositionLookupTable(const char *const dictPath, const bool isUpdatable)
: SingleDictContent(dictPath,

View File

@ -1,28 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LATINIME_HASH_MAP_COMPAT_H
#define LATINIME_HASH_MAP_COMPAT_H
#include <unordered_map>
#define hash_map_compat std::unordered_map
#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