mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
HashMap.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <cassert>
6
#include <functional>
7
#include <memory>
8
#include <optional>
9
#include <unordered_map>
10
#include <utility>
11
12
#include "
mini-llvm/utils/OptionalReference.h
"
13
14
namespace
mini_llvm
{
15
16
template
<
typename
Key,
17
typename
Value,
18
typename
Hash = std::hash<Key>,
19
typename
Equal = std::equal_to<Key>,
20
typename
Allocator = std::allocator<std::pair<const Key, Value>>>
21
class
HashMap
:
private
std::unordered_map<Key, Value, Hash, Equal, Allocator> {
22
using
Base = std::unordered_map<Key, Value, Hash, Equal, Allocator>;
23
24
public
:
25
using
typename Base::key_type;
26
using
typename Base::mapped_type;
27
using
typename Base::value_type;
28
using
typename Base::size_type;
29
using
typename Base::difference_type;
30
using
typename Base::hasher;
31
using
typename Base::key_equal;
32
using
typename Base::allocator_type;
33
using
typename Base::reference;
34
using
typename Base::const_reference;
35
using
typename Base::pointer;
36
using
typename Base::const_pointer;
37
using
typename Base::iterator;
38
using
typename Base::const_iterator;
39
using
typename Base::local_iterator;
40
using
typename Base::const_local_iterator;
41
using
typename Base::node_type;
42
using
typename Base::insert_return_type;
43
44
using
Base::Base;
45
using
Base::operator=;
46
using
Base::begin;
47
using
Base::end;
48
using
Base::cbegin;
49
using
Base::cend;
50
using
Base::empty;
51
using
Base::size;
52
using
Base::max_size;
53
using
Base::contains;
54
using
Base::count;
55
using
Base::at;
56
using
Base::find;
57
using
Base::equal_range;
58
using
Base::insert;
59
using
Base::insert_or_assign;
60
using
Base::emplace;
61
using
Base::emplace_hint;
62
using
Base::try_emplace;
63
using
Base::erase;
64
using
Base::clear;
65
using
Base::extract;
66
using
Base::merge;
67
using
Base::swap;
68
using
Base::bucket_count;
69
using
Base::max_bucket_count;
70
using
Base::bucket;
71
using
Base::bucket_size;
72
using
Base::load_factor;
73
using
Base::max_load_factor;
74
using
Base::rehash;
75
using
Base::reserve;
76
using
Base::hash_function;
77
using
Base::key_eq;
78
using
Base::get_allocator;
79
80
template
<
typename
Key2 = Key>
81
Value &
operator[]
(
const
Key2 &key) {
82
auto
i = find(key);
83
assert(i != end());
84
return
i->second;
85
}
86
87
template
<
typename
Key2 = Key>
88
const
Value &
operator[]
(
const
Key2 &key)
const
{
89
auto
i = find(key);
90
assert(i != end());
91
return
i->second;
92
}
93
94
template
<
typename
Key2 = Key>
95
OptionalReference<Value>
get
(
const
Key2 &key) {
96
auto
i = find(key);
97
if
(i != end()) {
98
return
i->second;
99
}
100
return
std::nullopt;
101
}
102
103
template
<
typename
Key2 = Key>
104
OptionalReference<const Value>
get
(
const
Key2 &key)
const
{
105
auto
i = find(key);
106
if
(i != end()) {
107
return
i->second;
108
}
109
return
std::nullopt;
110
}
111
112
template
<
typename
Key2 = Key,
typename
Value2 = Value>
113
std::pair<iterator, bool>
put
(Key2 &&key, Value2 &&value) {
114
return
insert_or_assign(std::forward<Key2>(key), std::forward<Value2>(value));
115
}
116
};
117
118
}
// namespace mini_llvm
OptionalReference.h
mini_llvm::HashMap
Definition
HashMap.h:21
mini_llvm::HashMap::operator[]
const Value & operator[](const Key2 &key) const
Definition
HashMap.h:88
mini_llvm::HashMap::get
OptionalReference< Value > get(const Key2 &key)
Definition
HashMap.h:95
mini_llvm::HashMap::put
std::pair< iterator, bool > put(Key2 &&key, Value2 &&value)
Definition
HashMap.h:113
mini_llvm::HashMap::operator[]
Value & operator[](const Key2 &key)
Definition
HashMap.h:81
mini_llvm::HashMap::get
OptionalReference< const Value > get(const Key2 &key) const
Definition
HashMap.h:104
mini_llvm::OptionalReference
Definition
OptionalReference.h:13
mini_llvm
Definition
GraphColoringAllocator.h:13
include
mini-llvm
utils
HashMap.h
Generated by
1.17.0