11 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
13 : _compare(compare), _container(allocator)
18 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
19 template <
class InputIterator>
21 :
FlatMap(capacity, compare, allocator)
26 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
28 :
FlatMap(flatmap.capacity(), flatmap._compare, flatmap._container.get_allocator())
30 for (
const auto& item : flatmap)
34 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
36 :
FlatMap(capacity, flatmap._compare, flatmap._container.get_allocator())
38 for (
const auto& item : flatmap)
42 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
46 reserve(flatmap.
size());
47 for (
const auto& item : flatmap)
52 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
56 if ((it != end()) && compare(key, it->first))
61 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
65 if ((it != end()) && compare(key, it->first))
70 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
73 return std::lower_bound(begin(), end(), key, [
this](
auto key1,
auto key2) {
return this->compare(key1, key2); });
76 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
79 return std::lower_bound(begin(), end(), key, [
this](
auto key1,
auto key2) {
return this->compare(key1, key2); });
82 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
85 return std::upper_bound(begin(), end(), key, [
this](
auto key1,
auto key2) {
return this->compare(key1, key2); });
88 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
91 return std::upper_bound(begin(), end(), key, [
this](
auto key1,
auto key2) {
return this->compare(key1, key2); });
94 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
95 inline std::pair<typename FlatMap<TKey, TValue, TCompare, TAllocator>::iterator,
typename FlatMap<TKey, TValue, TCompare, TAllocator>::iterator>
FlatMap<TKey, TValue, TCompare, TAllocator>::equal_range(
const TKey& key) noexcept
97 return std::equal_range(begin(), end(), key, [
this](
auto key1,
auto key2) {
return this->compare(key1, key2); });
100 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
101 inline std::pair<typename FlatMap<TKey, TValue, TCompare, TAllocator>::const_iterator,
typename FlatMap<TKey, TValue, TCompare, TAllocator>::const_iterator>
FlatMap<TKey, TValue, TCompare, TAllocator>::equal_range(
const TKey& key)
const noexcept
103 return std::equal_range(begin(), end(), key, [
this](
auto key1,
auto key2) {
return this->compare(key1, key2); });
106 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
111 throw std::out_of_range(
"Item with the given key was not found in the flat map!");
116 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
121 throw std::out_of_range(
"Item with the given key was not found in the flat map!");
126 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
129 return emplace_internal(item.first, item.second);
132 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
135 return emplace_internal(item.first, std::move(item.second));
138 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
141 return emplace_hint_internal(position, item.first, item.second);
144 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
147 return emplace_hint_internal(position, item.first, std::move(item.second));
150 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
151 template <
class InputIterator>
154 for (
auto it = first; it != last; ++it)
158 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
159 template <
typename... Args>
162 return emplace_internal(std::forward<Args>(args)...);
165 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
166 template <
typename... Args>
169 return emplace_hint_internal(position, std::forward<Args>(args)...);
172 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
179 _container.erase(it);
183 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
188 _container.erase(position);
192 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
196 _container.erase(first, last);
200 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
201 template <
typename... Args>
206 if ((it == end()) || compare(key, it->first))
208 it = _container.emplace(it, std::make_pair(key, TValue(std::forward<Args>(args)...)));
211 return std::make_pair(it, !found);
214 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
215 template <
typename... Args>
218 if (((position == begin()) || compare((position - 1)->first, key)) && ((position == end()) || compare(key, position.first)))
219 return _container.
emplace(position, std::make_pair(key, TValue(std::forward<Args>(args)...)));
220 return emplace_internal(key, std::forward<Args>(args)...).first;
223 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
227 swap(_compare, flatmap._compare);
228 swap(_container, flatmap._container);
231 template <
typename TKey,
typename TValue,
typename TCompare,
typename TAllocator>
234 flatmap1.swap(flatmap2);
FlatMap(size_t capacity=128, const TCompare &compare=TCompare(), const TAllocator &allocator=TAllocator())
Initialize the flat map with a given capacity.
void swap(FlatMap &flatmap) noexcept
Swap two instances.
std::pair< TKey, TValue > value_type
std::vector< value_type, TAllocator >::const_iterator const_iterator
std::pair< iterator, bool > insert(const value_type &item)
Insert a new item into the flat map.
void reserve(size_t count)
Reserve the flat map capacity to fit the given count of items.
std::vector< value_type, TAllocator >::iterator iterator
iterator find(const TKey &key) noexcept
Find the iterator which points to the first item with the given key in the flat map or return end ite...
iterator emplace_hint(const const_iterator &position, Args &&... args)
Emplace a new item into the flat map with a position hint.
mapped_type & at(const TKey &key) noexcept
Access to the item with the given key or throw std::out_of_range exception.
size_t capacity() const noexcept
Get the flat map capacity.
std::pair< iterator, iterator > equal_range(const TKey &key) noexcept
Find the bounds of a range that includes all the elements in the hash map with the given key.
FlatMap & operator=(const FlatMap &flatmap)
size_t erase(const TKey &key)
Erase the item with the given key from the flat map.
std::pair< iterator, bool > emplace(Args &&... args)
Emplace a new item into the flat map.
iterator upper_bound(const TKey &key) noexcept
Find the iterator which points to the first item with the given key that greater than the given key i...
size_t size() const noexcept
Get the flat map size.
iterator lower_bound(const TKey &key) noexcept
Find the iterator which points to the first item with the given key that not less than the given key ...
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept
void swap(FlatMap< TKey, TValue, TCompare, TAllocator > &flatmap1, FlatMap< TKey, TValue, TCompare, TAllocator > &flatmap2) noexcept