NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
flat_unordered_multimap.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_CONTAINER_FLAT_UNORDERED_MULTIMAP_HPP__
2#define NEFORCE_CORE_CONTAINER_FLAT_UNORDERED_MULTIMAP_HPP__
3
13
15NEFORCE_BEGIN_NAMESPACE__
16
22
39template <typename Key, typename T, typename HashFcn = hash<Key>, typename EqualKey = equal_to<Key>,
40 typename Alloc = allocator<pair<Key, T>>>
41class flat_unordered_multimap : public icollector<flat_unordered_multimap<Key, T, HashFcn, EqualKey, Alloc>> {
42 static_assert(is_hash_v<HashFcn, Key>, "flat_unordered_multimap requires valid hash function.");
43 static_assert(is_allocator_v<Alloc>, "Alloc type is not a standard allocator type.");
44 static_assert(is_object_v<Key>, "flat_unordered_multimap only contains object types.");
45
46private:
47 using base_type = flat_hashtable<pair<Key, T>, Key, HashFcn, select1st<pair<Key, T>>, EqualKey,
48 Alloc>;
49
50public:
51 using key_type = typename base_type::key_type;
52 using mapped_type = T;
54 using hasher = typename base_type::hasher;
56
60 using const_pointer = const value_type*;
62 using const_reference = const value_type&;
63 using iterator = typename base_type::iterator;
66
67private:
68 base_type ht_;
69
70public:
77
83 ht_(n) {}
84
91 ht_(n, hf) {}
92
99 flat_unordered_multimap(const size_type n, const hasher& hf, const key_equal& eql) :
100 ht_(n, hf, eql) {}
101
107 ht_(other.ht_) {}
108
115 ht_ = other.ht_;
116 return *this;
117 }
118
125
133 ht_ = _NEFORCE move(other.ht_);
134 return *this;
135 }
136
143 template <typename Iterator>
144 flat_unordered_multimap(Iterator first, Iterator last) :
145 ht_() {
146 ht_.insert_equal(first, last);
147 }
148
156 template <typename Iterator>
157 flat_unordered_multimap(Iterator first, Iterator last, const size_type n) :
158 ht_(n) {
159 ht_.insert_equal(first, last);
160 }
161
170 template <typename Iterator>
171 flat_unordered_multimap(Iterator first, Iterator last, const size_type n, const hasher& hf) :
172 ht_(n, hf) {
173 ht_.insert_equal(first, last);
174 }
175
185 template <typename Iterator>
186 flat_unordered_multimap(Iterator first, Iterator last, const size_type n, const hasher& hf, const key_equal& eql) :
187 ht_(n, hf, eql) {
188 ht_.insert_equal(first, last);
189 }
190
195 flat_unordered_multimap(std::initializer_list<value_type> ilist) :
196 flat_unordered_multimap(ilist.begin(), ilist.end()) {}
197
203 flat_unordered_multimap(std::initializer_list<value_type> ilist, const size_type n) :
204 flat_unordered_multimap(ilist.begin(), ilist.end(), n) {}
205
212 flat_unordered_multimap(std::initializer_list<value_type> ilist, const size_type n, const hasher& hf) :
213 flat_unordered_multimap(ilist.begin(), ilist.end(), n, hf) {}
214
222 flat_unordered_multimap(std::initializer_list<value_type> ilist, const size_type n, const hasher& hf,
223 const key_equal& eql) :
224 flat_unordered_multimap(ilist.begin(), ilist.end(), n, hf, eql) {}
225
230 NEFORCE_NODISCARD iterator begin() noexcept { return ht_.begin(); }
231
236 NEFORCE_NODISCARD iterator end() noexcept { return ht_.end(); }
237
242 NEFORCE_NODISCARD const_iterator begin() const noexcept { return ht_.begin(); }
243
248 NEFORCE_NODISCARD const_iterator end() const noexcept { return ht_.end(); }
249
254 NEFORCE_NODISCARD const_iterator cbegin() const noexcept { return ht_.cbegin(); }
255
260 NEFORCE_NODISCARD const_iterator cend() const noexcept { return ht_.cend(); }
261
266 NEFORCE_NODISCARD size_type size() const noexcept { return ht_.size(); }
267
272 NEFORCE_NODISCARD size_type max_size() const noexcept { return ht_.max_size(); }
273
278 NEFORCE_NODISCARD bool empty() const noexcept { return ht_.empty(); }
279
284 NEFORCE_NODISCARD size_type capacity() const noexcept { return ht_.capacity(); }
285
291 NEFORCE_NODISCARD size_type count(const key_type& key) const noexcept(noexcept(ht_.count(key))) {
292 return ht_.count(key);
293 }
294
300 NEFORCE_NODISCARD bool contains(const key_type& key) const noexcept(noexcept(ht_.contains(key))) {
301 return ht_.contains(key);
302 }
303
308 NEFORCE_NODISCARD hasher hash_function() const noexcept(noexcept(ht_.hash_function())) {
309 return ht_.hash_function();
310 }
311
316 NEFORCE_NODISCARD key_equal key_eql() const noexcept(noexcept(ht_.key_eql())) { return ht_.key_eql(); }
317
322 NEFORCE_NODISCARD float load_factor() const noexcept { return ht_.load_factor(); }
323
328 NEFORCE_NODISCARD float max_load_factor() const noexcept { return ht_.max_load_factor(); }
329
334 void max_load_factor(const float lf) noexcept { ht_.max_load_factor(lf); }
335
340 void rehash(const size_type n) { ht_.rehash(n); }
341
348 void reserve(const size_type n) { ht_.reserve(n); }
349
356 template <typename... Args>
357 iterator emplace(Args&&... args) {
358 return ht_.emplace_equal(_NEFORCE forward<Args>(args)...);
359 }
360
366 iterator insert(const value_type& value) { return ht_.insert_equal(value); }
367
373 iterator insert(value_type&& value) { return ht_.insert_equal(_NEFORCE move(value)); }
374
381 template <typename Iterator>
382 void insert(Iterator first, Iterator last) {
383 ht_.insert_equal(first, last);
384 }
385
390 void insert(std::initializer_list<value_type> ilist) { ht_.insert_equal(ilist); }
391
397 size_type erase(const key_type& key) noexcept { return ht_.erase(key); }
398
404 iterator erase(const iterator position) noexcept { return ht_.erase(position); }
405
412 iterator erase(const iterator first, const iterator last) noexcept { return ht_.erase(first, last); }
413
419 const_iterator erase(const const_iterator position) noexcept { return ht_.erase(position); }
420
427 const_iterator erase(const const_iterator first, const const_iterator last) noexcept {
428 return ht_.erase(first, last);
429 }
430
434 void clear() noexcept { ht_.clear(); }
435
441 NEFORCE_NODISCARD iterator find(const key_type& key) { return ht_.find(key); }
442
448 NEFORCE_NODISCARD const_iterator find(const key_type& key) const { return ht_.find(key); }
449
455 NEFORCE_NODISCARD pair<iterator, iterator> equal_range(const key_type& key) { return ht_.equal_range(key); }
456
462 NEFORCE_NODISCARD pair<const_iterator, const_iterator> equal_range(const key_type& key) const {
463 return ht_.equal_range(key);
464 }
465
470 void swap(flat_unordered_multimap& other) noexcept(is_nothrow_swappable_v<base_type>) { ht_.swap(other.ht_); }
471
477 NEFORCE_NODISCARD bool equal_to(const flat_unordered_multimap& rhs) const noexcept(noexcept(ht_ == rhs.ht_)) {
478 return ht_ == rhs.ht_;
479 }
480
486 NEFORCE_NODISCARD bool less_than(const flat_unordered_multimap& rhs) const noexcept(noexcept(ht_ < rhs.ht_)) {
487 return ht_ < rhs.ht_;
488 }
489};
490
491#ifdef NEFORCE_STANDARD_17
492template <typename Iterator, typename HashFcn = hash<iter_map_key_t<Iterator>>,
493 typename Compare = equal_to<iter_map_key_t<Iterator>>, typename Alloc>
494flat_unordered_multimap(Iterator, Iterator, HashFcn = HashFcn(), Compare = Compare(), Alloc = Alloc())
495 -> flat_unordered_multimap<iter_map_key_t<Iterator>, iter_map_value_t<Iterator>, HashFcn, Compare, Alloc>;
496
497template <typename Key, typename T, typename HashFcn = hash<Key>, typename Compare = equal_to<Key>,
498 typename Alloc = allocator<pair<Key, T>>>
499flat_unordered_multimap(std::initializer_list<pair<Key, T>>, HashFcn = HashFcn(), Compare = Compare(), Alloc = Alloc())
500 -> flat_unordered_multimap<Key, T, HashFcn, Compare, Alloc>;
501
502template <typename Iterator, typename Alloc>
503flat_unordered_multimap(Iterator, Iterator, Alloc)
504 -> flat_unordered_multimap<iter_map_key_t<Iterator>, iter_map_value_t<Iterator>, hash<iter_map_key_t<Iterator>>,
505 equal_to<iter_map_key_t<Iterator>>, Alloc>;
506
507template <typename Iterator, typename HashFcn, typename Alloc>
508flat_unordered_multimap(Iterator, Iterator, HashFcn, Alloc)
509 -> flat_unordered_multimap<iter_map_key_t<Iterator>, iter_map_value_t<Iterator>, HashFcn,
510 equal_to<iter_map_key_t<Iterator>>, Alloc>;
511
512template <typename Key, typename T, typename Alloc>
513flat_unordered_multimap(std::initializer_list<pair<Key, T>>, Alloc)
514 -> flat_unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Alloc>;
515
516template <typename Key, typename T, typename HashFcn, typename Alloc>
517flat_unordered_multimap(std::initializer_list<pair<Key, T>>, HashFcn, Alloc)
518 -> flat_unordered_multimap<Key, T, HashFcn, equal_to<Key>, Alloc>;
519#endif
520 // Container
522
523NEFORCE_END_NAMESPACE__
524#endif // NEFORCE_CORE_CONTAINER_FLAT_UNORDERED_MULTIMAP_HPP__
flat_unordered_multimap(std::initializer_list< value_type > ilist, const size_type n)
初始化列表构造函数,指定初始容量
flat_unordered_multimap()=default
默认构造函数
const_iterator cbegin() const noexcept
获取常量起始迭代器
typename base_type::const_iterator const_iterator
常量迭代器类型
flat_unordered_multimap(flat_unordered_multimap &&other) noexcept(is_nothrow_move_constructible_v< base_type >)
移动构造函数
void insert(Iterator first, Iterator last)
范围插入元素
iterator insert(value_type &&value)
移动插入元素
size_type max_size() const noexcept
获取最大可能大小
iterator erase(const iterator first, const iterator last) noexcept
删除指定范围内的元素
flat_unordered_multimap(Iterator first, Iterator last, const size_type n, const hasher &hf)
范围构造函数,指定初始容量和哈希函数
const_iterator end() const noexcept
获取常量结束迭代器
flat_unordered_multimap & operator=(flat_unordered_multimap &&other) noexcept(is_nothrow_move_assignable_v< base_type >)
移动赋值运算符
const_iterator erase(const const_iterator first, const const_iterator last) noexcept
删除指定范围内的常量元素
pair< const_iterator, const_iterator > equal_range(const key_type &key) const
获取等于指定键的常量元素范围
iterator begin() noexcept
获取起始迭代器
size_type size() const noexcept
获取元素数量
const_iterator find(const key_type &key) const
查找具有指定键的常量元素
hasher hash_function() const noexcept(noexcept(ht_.hash_function()))
获取哈希函数对象
flat_unordered_multimap(Iterator first, Iterator last, const size_type n, const hasher &hf, const key_equal &eql)
范围构造函数,指定初始容量、哈希函数和键相等比较函数
bool contains(const key_type &key) const noexcept(noexcept(ht_.contains(key)))
检查是否包含指定键
flat_unordered_multimap(const flat_unordered_multimap &other)
拷贝构造函数
void insert(std::initializer_list< value_type > ilist)
初始化列表插入元素
iterator end() noexcept
获取结束迭代器
size_type capacity() const noexcept
获取容量
flat_unordered_multimap(std::initializer_list< value_type > ilist, const size_type n, const hasher &hf)
初始化列表构造函数,指定初始容量和哈希函数
typename base_type::key_type key_type
键类型
const_iterator begin() const noexcept
获取常量起始迭代器
iterator find(const key_type &key)
查找具有指定键的元素
flat_unordered_multimap(const size_type n, const hasher &hf, const key_equal &eql)
构造函数,指定初始容量、哈希函数和键相等比较函数
typename base_type::difference_type difference_type
差值类型
flat_unordered_multimap(Iterator first, Iterator last, const size_type n)
范围构造函数,指定初始容量
float load_factor() const noexcept
获取当前负载因子
float max_load_factor() const noexcept
获取最大负载因子
bool less_than(const flat_unordered_multimap &rhs) const noexcept(noexcept(ht_< rhs.ht_))
小于比较操作符
const_iterator erase(const const_iterator position) noexcept
删除指定位置的常量元素
iterator insert(const value_type &value)
插入元素(拷贝版本)
const value_type * const_pointer
常量指针类型
size_type erase(const key_type &key) noexcept
删除所有具有指定键的元素
size_type count(const key_type &key) const noexcept(noexcept(ht_.count(key)))
统计具有指定键的元素数量
flat_unordered_multimap(const size_type n, const hasher &hf)
构造函数,指定初始容量和哈希函数
flat_unordered_multimap(std::initializer_list< value_type > ilist)
初始化列表构造函数
void max_load_factor(const float lf) noexcept
设置最大负载因子
typename base_type::allocator_type allocator_type
分配器类型
typename base_type::iterator iterator
迭代器类型
flat_unordered_multimap & operator=(const flat_unordered_multimap &other)
拷贝赋值运算符
typename base_type::size_type size_type
大小类型
typename base_type::key_equal key_equal
键相等比较函数类型
key_equal key_eql() const noexcept(noexcept(ht_.key_eql()))
获取键相等比较函数对象
bool equal_to(const flat_unordered_multimap &rhs) const noexcept(noexcept(ht_==rhs.ht_))
相等比较操作符
void rehash(const size_type n)
重新哈希,调整容量
void swap(flat_unordered_multimap &other) noexcept(is_nothrow_swappable_v< base_type >)
交换两个容器
iterator erase(const iterator position) noexcept
删除指定位置的元素
const_iterator cend() const noexcept
获取常量结束迭代器
flat_unordered_multimap(std::initializer_list< value_type > ilist, const size_type n, const hasher &hf, const key_equal &eql)
初始化列表构造函数,指定初始容量、哈希函数和键相等比较函数
typename base_type::hasher hasher
哈希函数类型
pair< iterator, iterator > equal_range(const key_type &key)
获取等于指定键的元素范围
bool empty() const noexcept
检查是否为空
const value_type & const_reference
常量引用类型
void reserve(const size_type n)
预留空间
flat_unordered_multimap(const size_type n)
构造函数,指定初始容量
iterator emplace(Args &&... args)
在容器中就地构造元素
flat_unordered_multimap(Iterator first, Iterator last)
范围构造函数
平坦哈希表容器
constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
constexpr bool is_object_v
is_object的便捷变量模板
constexpr bool is_hash_v
is_hash的便捷变量模板
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
constexpr bool is_nothrow_swappable_v
is_nothrow_swappable的便捷变量模板
constexpr bool is_allocator_v
is_allocator的便捷变量模板
constexpr bool is_nothrow_move_assignable_v
is_nothrow_move_assignable的便捷变量模板
constexpr bool is_nothrow_move_constructible_v
is_nothrow_move_constructible的便捷变量模板
集合器接口模板
存储两个值的元组对
选择pair的第一个元素