NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
unordered_multiset.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_CONTAINER_UNORDERED_MULTISET_HPP__
2#define NEFORCE_CORE_CONTAINER_UNORDERED_MULTISET_HPP__
3
13
15NEFORCE_BEGIN_NAMESPACE__
16
22
35template <typename Value, typename HashFcn = hash<Value>, typename EqualKey = equal_to<Value>,
36 typename Alloc = allocator<hashtable_node<Value>>>
37class unordered_multiset : icollector<unordered_multiset<Value, HashFcn, EqualKey, Alloc>> {
38 static_assert(is_hash_v<HashFcn, Value>, "unordered multiset requires valid hash function.");
39 static_assert(is_allocator_v<Alloc>, "Alloc type is not a standard allocator type.");
40 static_assert(is_same_v<hashtable_node<Value>, typename Alloc::value_type>, "allocator type mismatch.");
41 static_assert(is_object_v<Value>, "unordered multiset only contains object types.");
42
43private:
44 using base_type = hashtable<Value, Value, HashFcn, identity<Value>, EqualKey, Alloc>;
45
46public:
47 using key_type = typename base_type::key_type;
49 using hasher = typename base_type::hasher;
51
58 using iterator = typename base_type::iterator;
61
62private:
63 base_type ht_{100};
64
65public:
72 ht_(100, hasher(), key_equal()) {}
73
79 ht_(n) {}
80
87 ht_(n, hf, key_equal()) {}
88
95 unordered_multiset(size_type n, const hasher& hf, const key_equal& eql) :
96 ht_(n, hf, eql) {}
97
103 ht_(other.ht_) {}
104
111 ht_ = other.ht_;
112 return *this;
113 }
114
120 ht_(_NEFORCE move(other.ht_)) {}
121
128 ht_ = _NEFORCE move(other.ht_);
129 return *this;
130 }
131
138 template <typename Iterator>
139 unordered_multiset(Iterator first, Iterator last) :
140 ht_(100, hasher(), key_equal()) {
141 ht_.insert_equal(first, last);
142 }
143
151 template <typename Iterator>
152 unordered_multiset(Iterator first, Iterator list, size_type n) :
153 ht_(n, hasher(), key_equal()) {
154 ht_.insert_equal(first, list);
155 }
156
165 template <typename Iterator>
166 unordered_multiset(Iterator first, Iterator last, size_type n, const hasher& hf) :
167 ht_(n, hf, key_equal()) {
168 ht_.insert_equal(first, last);
169 }
170
180 template <typename Iterator>
181 unordered_multiset(Iterator first, Iterator last, size_type n, const hasher& hf, const key_equal& eql) :
182 ht_(n, hf, eql) {
183 ht_.insert_equal(first, last);
184 }
185
190 unordered_multiset(std::initializer_list<value_type> ilist) :
191 unordered_multiset(ilist.begin(), ilist.end()) {}
192
198 unordered_multiset(std::initializer_list<value_type> ilist, size_type n) :
199 unordered_multiset(ilist.begin(), ilist.end(), n) {}
200
207 unordered_multiset(std::initializer_list<value_type> ilist, size_type n, const hasher& hf) :
208 unordered_multiset(ilist.begin(), ilist.end(), n, hf) {}
209
217 unordered_multiset(std::initializer_list<value_type> ilist, size_type n, const hasher& hf, const key_equal& eql) :
218 unordered_multiset(ilist.begin(), ilist.end(), n, hf, eql) {}
219
224 NEFORCE_NODISCARD iterator begin() noexcept { return ht_.begin(); }
225
230 NEFORCE_NODISCARD iterator end() noexcept { return ht_.end(); }
231
236 NEFORCE_NODISCARD const_iterator begin() const noexcept { return ht_.begin(); }
237
242 NEFORCE_NODISCARD const_iterator end() const noexcept { return ht_.end(); }
243
248 NEFORCE_NODISCARD const_iterator cbegin() const noexcept { return ht_.cbegin(); }
249
254 NEFORCE_NODISCARD const_iterator cend() const noexcept { return ht_.cend(); }
255
260 NEFORCE_NODISCARD size_type size() const noexcept { return ht_.size(); }
261
266 NEFORCE_NODISCARD size_type max_size() const noexcept { return ht_.max_size(); }
267
272 NEFORCE_NODISCARD bool empty() const noexcept { return ht_.empty(); }
273
279 NEFORCE_NODISCARD size_type count(const key_type& key) const noexcept(noexcept(ht_.count(key))) {
280 return ht_.count(key);
281 }
282
287 NEFORCE_NODISCARD size_type buckets_size() const noexcept { return ht_.buckets_size(); }
288
293 NEFORCE_NODISCARD size_type buckets_max_count() const noexcept { return ht_.buckets_max_count(); }
294
300 NEFORCE_NODISCARD size_type bucket_size(size_type n) const noexcept { return ht_.bucket_size(n); }
301
306 NEFORCE_NODISCARD hasher hash_func() const noexcept(noexcept(ht_.hash_func())) { return ht_.hash_func(); }
307
312 NEFORCE_NODISCARD key_equal key_eql() const noexcept(noexcept(ht_.key_eql())) { return ht_.key_eql(); }
313
318 NEFORCE_NODISCARD float load_factor() const noexcept { return ht_.load_factor(); }
319
324 NEFORCE_NODISCARD float max_load_factor() const noexcept { return ht_.max_load_factor(); }
325
330 void max_load_factor(float lf) noexcept { ht_.max_load_factor(lf); }
331
336 void rehash(size_type n) { ht_.rehash(n); }
337
344 void reserve(size_type n) { ht_.reserve(n); }
345
352 template <typename... Args>
353 iterator emplace(Args&&... args) {
354 return ht_.emplace_equal(_NEFORCE forward<Args>(args)...);
355 }
356
362 iterator insert(const value_type& value) { return ht_.insert_equal(value); }
363
369 iterator insert(value_type&& value) { return ht_.insert_equal(_NEFORCE move(value)); }
370
377 template <typename Iterator>
378 void insert(Iterator first, Iterator last) {
379 ht_.insert_equal(first, last);
380 }
381
387 size_type erase(const key_type& key) noexcept { return ht_.erase(key); }
388
393 void erase(iterator position) noexcept { ht_.erase(position); }
394
400 void erase(iterator first, iterator last) noexcept { ht_.erase(first, last); }
401
405 void clear() noexcept { ht_.clear(); }
406
411 void swap(unordered_multiset& other) noexcept(is_nothrow_swappable_v<base_type>) { ht_.swap(other.ht_); }
412
418 NEFORCE_NODISCARD iterator find(const key_type& key) { return ht_.find(key); }
419
425 NEFORCE_NODISCARD const_iterator find(const key_type& key) const { return ht_.find(key); }
426
432 NEFORCE_NODISCARD pair<iterator, iterator> equal_range(const key_type& key) { return ht_.equal_range(key); }
433
439 NEFORCE_NODISCARD pair<const_iterator, const_iterator> equal_range(const key_type& key) const {
440 return ht_.equal_range(key);
441 }
442
448 NEFORCE_NODISCARD bool operator==(const unordered_multiset& rhs) const noexcept(noexcept(ht_ == rhs.ht_)) {
449 return ht_ == rhs.ht_;
450 }
451
457 NEFORCE_NODISCARD bool operator<(const unordered_multiset& rhs) const noexcept(noexcept(ht_ < rhs.ht_)) {
458 return ht_ < rhs.ht_;
459 }
460};
461
462#ifdef NEFORCE_STANDARD_17
463template <typename Iterator, typename HashFcn = hash<iter_value_t<Iterator>>,
464 typename Compare = equal_to<iter_value_t<Iterator>>, typename Alloc = allocator<iter_value_t<Iterator>>>
465unordered_multiset(Iterator, Iterator, HashFcn = HashFcn(), Compare = Compare(), Alloc = Alloc())
466 -> unordered_multiset<iter_value_t<Iterator>, HashFcn, Compare, Alloc>;
467
468template <typename Value, typename HashFcn = hash<Value>, typename Compare = equal_to<Value>,
469 typename Alloc = allocator<Value>>
470unordered_multiset(std::initializer_list<Value>, HashFcn = HashFcn(), Compare = Compare(), Alloc = Alloc())
472
473template <typename Iterator, typename Alloc>
474unordered_multiset(Iterator, Iterator, Alloc)
476 Alloc>;
477
478template <typename Iterator, typename HashFcn, typename Alloc>
479unordered_multiset(Iterator, Iterator, HashFcn, Alloc)
481
482template <typename Value, typename Alloc>
483unordered_multiset(std::initializer_list<Value>, Alloc)
485
486template <typename Value, typename HashFcn, typename Alloc>
487unordered_multiset(std::initializer_list<Value>, HashFcn, Alloc)
489#endif
490 // Container
492
493NEFORCE_END_NAMESPACE__
494#endif // NEFORCE_CORE_CONTAINER_UNORDERED_MULTISET_HPP__
哈希表容器
双向链表容器
无序多重集合容器
void erase(iterator first, iterator last) noexcept
删除指定范围内的元素
unordered_multiset(size_type n, const hasher &hf)
构造函数,指定初始桶数和哈希函数
void reserve(size_type n)
预留空间
NEFORCE_NODISCARD size_type count(const key_type &key) const noexcept(noexcept(ht_.count(key)))
统计具有指定键的元素数量
NEFORCE_NODISCARD bool operator==(const unordered_multiset &rhs) const noexcept(noexcept(ht_==rhs.ht_))
相等比较操作符
NEFORCE_NODISCARD const_iterator begin() const noexcept
获取常量起始迭代器
typename base_type::const_reference reference
引用类型
unordered_multiset(std::initializer_list< value_type > ilist)
初始化列表构造函数
NEFORCE_NODISCARD bool operator<(const unordered_multiset &rhs) const noexcept(noexcept(ht_< rhs.ht_))
小于比较操作符
NEFORCE_NODISCARD const_iterator end() const noexcept
获取常量结束迭代器
typename base_type::const_iterator const_iterator
常量迭代器类型
typename base_type::const_reference const_reference
常量引用类型
NEFORCE_NODISCARD size_type max_size() const noexcept
获取最大可能大小
unordered_multiset(Iterator first, Iterator last, size_type n, const hasher &hf, const key_equal &eql)
范围构造函数,指定初始桶数、哈希函数和键相等比较函数
unordered_multiset & operator=(const unordered_multiset &other)
拷贝赋值运算符
iterator insert(value_type &&value)
移动插入元素
typename base_type::allocator_type allocator_type
分配器类型
NEFORCE_NODISCARD const_iterator cend() const noexcept
获取常量结束迭代器
NEFORCE_NODISCARD pair< iterator, iterator > equal_range(const key_type &key)
获取等于指定键的元素范围
unordered_multiset(const unordered_multiset &other)
拷贝构造函数
unordered_multiset(std::initializer_list< value_type > ilist, size_type n, const hasher &hf)
初始化列表构造函数,指定初始桶数和哈希函数
unordered_multiset(std::initializer_list< value_type > ilist, size_type n, const hasher &hf, const key_equal &eql)
初始化列表构造函数,指定初始桶数、哈希函数和键相等比较函数
typename base_type::const_pointer pointer
指针类型
typename base_type::size_type size_type
大小类型
void swap(unordered_multiset &other) noexcept(is_nothrow_swappable_v< base_type >)
交换两个unordered_multiset的内容
typename base_type::key_equal key_equal
键相等比较函数类型
NEFORCE_NODISCARD size_type size() const noexcept
获取元素数量
NEFORCE_NODISCARD float load_factor() const noexcept
获取当前负载因子
NEFORCE_NODISCARD size_type buckets_size() const noexcept
获取桶数量
NEFORCE_NODISCARD hasher hash_func() const noexcept(noexcept(ht_.hash_func()))
获取哈希函数对象
NEFORCE_NODISCARD bool empty() const noexcept
检查是否为空
NEFORCE_NODISCARD iterator begin() noexcept
获取起始迭代器
NEFORCE_NODISCARD key_equal key_eql() const noexcept(noexcept(ht_.key_eql()))
获取键相等比较函数对象
NEFORCE_NODISCARD size_type bucket_size(size_type n) const noexcept
获取指定桶的大小
typename base_type::hasher hasher
哈希函数类型
NEFORCE_NODISCARD const_iterator cbegin() const noexcept
获取常量起始迭代器
unordered_multiset(size_type n)
构造函数,指定初始桶数
unordered_multiset(std::initializer_list< value_type > ilist, size_type n)
初始化列表构造函数,指定初始桶数
unordered_multiset(Iterator first, Iterator last)
范围构造函数
void rehash(size_type n)
重新哈希,调整桶数量
typename base_type::difference_type difference_type
差值类型
unordered_multiset(Iterator first, Iterator list, size_type n)
范围构造函数,指定初始桶数
unordered_multiset(size_type n, const hasher &hf, const key_equal &eql)
构造函数,指定初始桶数、哈希函数和键相等比较函数
NEFORCE_NODISCARD size_type buckets_max_count() const noexcept
获取最大桶数量
void clear() noexcept
清空unordered_multiset
typename base_type::value_type value_type
值类型
unordered_multiset(unordered_multiset &&other) noexcept(is_nothrow_move_constructible_v< base_type >)
移动构造函数
typename base_type::key_type key_type
键类型
void erase(iterator position) noexcept
删除指定位置的元素
size_type erase(const key_type &key) noexcept
删除所有具有指定键的元素
typename base_type::iterator iterator
迭代器类型
void max_load_factor(float lf) noexcept
设置最大负载因子
void insert(Iterator first, Iterator last)
范围插入元素
unordered_multiset()
默认构造函数
NEFORCE_NODISCARD iterator end() noexcept
获取结束迭代器
NEFORCE_NODISCARD float max_load_factor() const noexcept
获取最大负载因子
iterator emplace(Args &&... args)
在unordered_multiset中就地构造元素
NEFORCE_NODISCARD pair< const_iterator, const_iterator > equal_range(const key_type &key) const
获取等于指定键的常量元素范围
typename base_type::const_pointer const_pointer
常量指针类型
NEFORCE_NODISCARD const_iterator find(const key_type &key) const
查找具有指定键的常量元素
NEFORCE_NODISCARD iterator find(const key_type &key)
查找具有指定键的元素
iterator insert(const value_type &value)
拷贝插入元素
unordered_multiset & operator=(unordered_multiset &&other) noexcept(is_nothrow_move_assignable_v< base_type >)
移动赋值运算符
unordered_multiset(Iterator first, Iterator last, size_type n, const hasher &hf)
范围构造函数,指定初始桶数和哈希函数
NEFORCE_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
NEFORCE_INLINE17 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)))
移动范围元素
NEFORCE_INLINE17 constexpr bool is_nothrow_swappable_v
is_nothrow_swappable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_allocator_v
is_allocator的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_move_assignable_v
is_nothrow_move_assignable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_move_constructible_v
is_nothrow_move_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_same_v
is_same的便捷变量模板
哈希表容器
相等比较仿函数
哈希函数的主模板
集合器接口模板
存储两个值的元组对