| Index: src/base/hashmap.h
|
| diff --git a/src/base/hashmap.h b/src/base/hashmap.h
|
| index ce72f84d2ad05a3f1b4e5d03fa80b9e208f7e774..d8151861cbe070457560602aab02768927d60b93 100644
|
| --- a/src/base/hashmap.h
|
| +++ b/src/base/hashmap.h
|
| @@ -36,8 +36,8 @@ class TemplateHashMapImpl {
|
|
|
| // initial_capacity is the size of the initial hash map;
|
| // it must be a power of 2 (and thus must not be 0).
|
| - TemplateHashMapImpl(MatchFun match = MatchFun(),
|
| - uint32_t capacity = kDefaultHashMapCapacity,
|
| + TemplateHashMapImpl(uint32_t capacity = kDefaultHashMapCapacity,
|
| + MatchFun match = MatchFun(),
|
| AllocationPolicy allocator = AllocationPolicy());
|
|
|
| ~TemplateHashMapImpl();
|
| @@ -93,6 +93,8 @@ class TemplateHashMapImpl {
|
| Entry* map_;
|
| uint32_t capacity_;
|
| uint32_t occupancy_;
|
| + // TODO(leszeks): This takes up space even if it has no state, maybe replace
|
| + // with something that does the empty base optimisation e.g. std::tuple
|
| MatchFun match_;
|
|
|
| Entry* map_end() const { return map_ + capacity_; }
|
| @@ -106,7 +108,7 @@ class TemplateHashMapImpl {
|
| template <typename Key, typename Value, typename MatchFun,
|
| class AllocationPolicy>
|
| TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::
|
| - TemplateHashMapImpl(MatchFun match, uint32_t initial_capacity,
|
| + TemplateHashMapImpl(uint32_t initial_capacity, MatchFun match,
|
| AllocationPolicy allocator)
|
| : match_(match) {
|
| Initialize(initial_capacity, allocator);
|
| @@ -336,7 +338,7 @@ void TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Resize(
|
| }
|
|
|
| template <typename AllocationPolicy>
|
| -class PointerTemplateHashMapImpl
|
| +class CustomMatcherTemplateHashMapImpl
|
| : public TemplateHashMapImpl<void*, void*, bool (*)(void*, void*),
|
| AllocationPolicy> {
|
| typedef TemplateHashMapImpl<void*, void*, bool (*)(void*, void*),
|
| @@ -346,24 +348,38 @@ class PointerTemplateHashMapImpl
|
| public:
|
| typedef bool (*MatchFun)(void*, void*);
|
|
|
| - PointerTemplateHashMapImpl(MatchFun match = PointersMatch,
|
| - uint32_t capacity = Base::kDefaultHashMapCapacity,
|
| - AllocationPolicy allocator = AllocationPolicy())
|
| - : Base(match, capacity, allocator) {}
|
| + CustomMatcherTemplateHashMapImpl(
|
| + MatchFun match, uint32_t capacity = Base::kDefaultHashMapCapacity,
|
| + AllocationPolicy allocator = AllocationPolicy())
|
| + : Base(capacity, match, allocator) {}
|
| +};
|
| +
|
| +typedef CustomMatcherTemplateHashMapImpl<DefaultAllocationPolicy>
|
| + CustomMatcherHashMap;
|
| +
|
| +template <typename AllocationPolicy>
|
| +class PointerTemplateHashMapImpl
|
| + : public TemplateHashMapImpl<void*, void*, std::equal_to<void*>,
|
| + AllocationPolicy> {
|
| + typedef TemplateHashMapImpl<void*, void*, std::equal_to<void*>,
|
| + AllocationPolicy>
|
| + Base;
|
|
|
| - static bool PointersMatch(void* key1, void* key2) { return key1 == key2; }
|
| + public:
|
| + PointerTemplateHashMapImpl(uint32_t capacity = Base::kDefaultHashMapCapacity,
|
| + AllocationPolicy allocator = AllocationPolicy())
|
| + : Base(capacity, std::equal_to<void*>(), allocator) {}
|
| };
|
|
|
| typedef PointerTemplateHashMapImpl<DefaultAllocationPolicy> HashMap;
|
|
|
| // A hash map for pointer keys and values with an STL-like interface.
|
| -template <class Key, class Value, class AllocationPolicy>
|
| -class TemplateHashMap : private PointerTemplateHashMapImpl<AllocationPolicy> {
|
| - typedef PointerTemplateHashMapImpl<AllocationPolicy> Base;
|
| +template <class Key, class Value, class MatchFun, class AllocationPolicy>
|
| +class TemplateHashMap
|
| + : private TemplateHashMapImpl<void*, void*, MatchFun, AllocationPolicy> {
|
| + typedef TemplateHashMapImpl<void*, void*, MatchFun, AllocationPolicy> Base;
|
|
|
| public:
|
| - typedef bool (*MatchFun)(void*, void*);
|
| -
|
| STATIC_ASSERT(sizeof(Key*) == sizeof(void*)); // NOLINT
|
| STATIC_ASSERT(sizeof(Value*) == sizeof(void*)); // NOLINT
|
| struct value_type {
|
| @@ -393,7 +409,7 @@ class TemplateHashMap : private PointerTemplateHashMapImpl<AllocationPolicy> {
|
|
|
| TemplateHashMap(MatchFun match,
|
| AllocationPolicy allocator = AllocationPolicy())
|
| - : Base(match, Base::kDefaultHashMapCapacity, allocator) {}
|
| + : Base(Base::kDefaultHashMapCapacity, match, allocator) {}
|
|
|
| Iterator begin() const { return Iterator(this, this->Start()); }
|
| Iterator end() const { return Iterator(this, nullptr); }
|
|
|