Skip to content
Permalink
Browse files

Remove legacy base/hash_tables.h in favor of C++11

With this CL all the uses of base/hash_tables.h are replaced with std::unordered_set and std::unordered_map in favor of C++11.

No user-visible behavior change is intended.

BUG=none
TEST=unittest

git-svn-id: https://mozc.googlecode.com/svn/trunk@521 a6090854-d499-a067-5803-1114d4e51264
  • Loading branch information...
yukawa committed Jan 31, 2015
1 parent 091dc3b commit 6895df10f02dafb86150da8a3cc65f051f70e054
@@ -126,7 +126,6 @@
'sources': [
'bitarray_test.cc',
'flags_test.cc',
'hash_tables_test.cc',
'iterator_adapter_test.cc',
'logging_test.cc',
'mmap_test.cc',

This file was deleted.

This file was deleted.

@@ -31,11 +31,11 @@

#include <cstring>
#include <string>
#include <unordered_set>
#include <vector>

#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/util.h"
#include "converter/connector_base.h"
@@ -210,7 +210,7 @@ void DataManagerTestBase::SuggestionFilterTest_IsBadSuggestion() {
}

// Load the original suggestion filter from file.
hash_set<string> suggestion_filter_set;
std::unordered_set<string> suggestion_filter_set;

vector<string> files;
Util::SplitStringUsing(suggestion_filter_files_, ",", &files);
@@ -33,10 +33,10 @@
#include <climits>
#include <cstring>
#include <sstream>
#include <unordered_set>

#include "base/file_stream.h"
#include "base/flags.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/util.h"
#include "dictionary/dictionary_token.h"
@@ -202,7 +202,7 @@ bool HasHomonymsInSamePos(
return false;
}

hash_set<uint32> seen;
std::unordered_set<uint32> seen;
for (size_t i = 0; i < key_info.tokens.size(); ++i) {
const Token *token = key_info.tokens[i].token;
const uint32 pos = GetCombinedPos(token->lid, token->rid);
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=16
BUILD=2037
BUILD=2038
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.
@@ -30,13 +30,13 @@
#include "prediction/suggestion_filter.h"

#include <set>
#include <vector>
#include <string>
#include <unordered_set>
#include <vector>

#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/flags.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/util.h"
#include "testing/base/public/googletest.h"
@@ -69,7 +69,7 @@ const double kErrorRatio = 0.0001;

TEST(SuggestionFilter, IsBadSuggestionTest) {
// Load suggestion_filter
hash_set<string> suggestion_filter_set;
std::unordered_set<string> suggestion_filter_set;

vector<string> files;
Util::SplitStringUsing(FLAGS_suggestion_filter_files, ",", &files);
@@ -38,9 +38,9 @@

#include <memory>
#include <string>
#include <unordered_map>

#include "base/const.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/port.h"
#include "base/process.h"
@@ -239,7 +239,7 @@ CComPtr<ITfCategoryMgr> GetCategoryMgr() {

// Custom hash function for ATL::CComPtr.
template <typename T>
struct CComPtrHashCompare : public hash_compare<CComPtr<T>> {
struct CComPtrHash {
size_t operator()(const CComPtr<T> &value) const {
// Caveats: On x86 environment, both _M_X64 and _M_IX86 are defined. So we
// need to check _M_X64 first.
@@ -253,20 +253,14 @@ struct CComPtrHashCompare : public hash_compare<CComPtr<T>> {
// Compress the data by shifting unused bits.
return reinterpret_cast<size_t>(value.p) >> kUnusedBits;
}
bool operator()(const CComPtr<T> &value1, const CComPtr<T> &value2) const {
return value1 != value2;
}
};

// Custom hash function for GUID.
struct GuidHashCompare : public hash_compare<GUID> {
struct GuidHash {
size_t operator()(const GUID &value) const {
// Compress the data by shifting unused bits.
return value.Data1;
}
bool operator()(const GUID &value1, const GUID &value2) const {
return !::IsEqualGUID(value1, value2);
}
};

// An observer that binds ITfCompositionSink::OnCompositionTerminated callback
@@ -1785,10 +1779,10 @@ class TipTextServiceImpl
// Used for LangBar integration.
TipLangBar langbar_;

typedef hash_map<GUID, UINT, GuidHashCompare> PreservedKeyMap;
typedef hash_map<CComPtr<ITfContext>,
TipPrivateContext *,
CComPtrHashCompare<ITfContext>> PrivateContextMap;
using PreservedKeyMap = std::unordered_map<GUID, UINT, GuidHash>;
using PrivateContextMap = std::unordered_map<CComPtr<ITfContext>,
TipPrivateContext *,
CComPtrHash<ITfContext>>;
PrivateContextMap private_context_map_;
PreservedKeyMap preserved_key_map_;
unique_ptr<TipThreadContext> thread_context_;
@@ -40,8 +40,8 @@
#include <msctf.h>

#include <memory>
#include <unordered_map>

#include "base/hash_tables.h"
#include "base/util.h"
#include "renderer/table_layout.h"
#include "renderer/win32/text_renderer.h"
@@ -607,9 +607,7 @@ HWND GetOwnerWindow(ITfContext *context) {
return window_handle;
}

class WindowMap
: public hash_map<HWND, TipImmersiveUiElementImpl *> {
};
using WindowMap = std::unordered_map<HWND, TipImmersiveUiElementImpl *>;

class ThreadLocalInfo {
public:
@@ -36,7 +36,8 @@
#include <atlstr.h>
#include <msctf.h>

#include "base/hash_tables.h"
#include <unordered_map>

#include "renderer/renderer_command.pb.h"
#include "session/commands.pb.h"
#include "win32/base/input_state.h"
@@ -93,7 +94,8 @@ HRESULT EndUI(ITfUIElementMgr *ui_element_manager, DWORD element_id) {
} // namespace

class TipUiElementManager::UiElementMap
: public hash_map<TipUiElementManager::UIElementFlags, UIElementInfo> {
: public std::unordered_map<TipUiElementManager::UIElementFlags,
UIElementInfo> {
};

TipUiElementManager::TipUiElementManager()
@@ -38,7 +38,8 @@
#include <atlwin.h>
#include <msctf.h>

#include "base/hash_tables.h"
#include <unordered_map>

#include "base/util.h"
#include "session/commands.pb.h"
#include "win32/tip/tip_composition_util.h"
@@ -74,37 +75,7 @@ volatile bool g_module_unloaded = false;
// value, the current thread is initialized.
volatile DWORD g_tls_index = TLS_OUT_OF_INDEXES;

// Visual C++ 2008 requires this.
#if 1310 <= _MSC_VER || _MSC_VER < 1600
using stdext::hash_compare;
#endif // 1310 <= _MSC_VER < 1600

// Custom hash function for ATL::CComPtr.
template <typename T>
struct PtrHashCompare : public hash_compare<T> {
std::size_t operator()(const T &value) const {
// Caveats: On x86 environment, both _M_X64 and _M_IX86 are defined. So we
// need to check _M_X64 first.
#if defined(_M_X64)
const size_t kUnusedBits = 3; // assuming 8-byte aligned
#elif defined(_M_IX86)
const size_t kUnusedBits = 2; // assuming 4-byte aligned
#else
#error "unsupported platform"
#endif
// Compress the data by shifting unused bits.
return reinterpret_cast<size_t>(value) >> kUnusedBits;
}
bool operator()(const T &value1, const T &value2) const {
return value1 != value2;
}
};

class UiElementMap
: public hash_map<ITfUIElement *,
HWND,
PtrHashCompare<IUnknown *> > {
};
using UiElementMap = std::unordered_map<ITfUIElement *, HWND>;

class ThreadLocalInfo {
public:

0 comments on commit 6895df1

Please sign in to comment.
You can’t perform that action at this time.