-
Notifications
You must be signed in to change notification settings - Fork 0
/
unordered_set.hpp
71 lines (60 loc) · 2.45 KB
/
unordered_set.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _ASP_UNORDERED_SET_HPP_
#define _ASP_UNORDERED_SET_HPP_
#include <functional>
#include "basic_param.hpp"
#include "hash_table.hpp"
namespace asp {
template <typename _Tp,
typename _Hash = std::hash<_Tp>,
typename _Alloc = std::allocator<_Tp>
> class unordered_set;
template <typename _Tp, typename _Hash, typename _Alloc>
class unordered_set {
typedef unordered_set<_Tp, _Hash, _Alloc> self;
typedef hash_table<_Tp, _Tp, _select_self, true, _select_self, _Hash, _Alloc> uset_ht;
uset_ht _h;
public:
typedef typename uset_ht::key_type key_type;
typedef typename uset_ht::value_type value_type;
typedef typename uset_ht::mapped_type mapped_type;
typedef typename uset_ht::hasher hasher;
typedef typename uset_ht::iterator iterator;
typedef typename uset_ht::const_iterator const_iterator;
typedef typename uset_ht::ireturn_type ireturn_type;
typedef typename uset_ht::insert_status insert_status;
typedef typename uset_ht::ext_iterator ext_iterator;
typedef typename uset_ht::ext_key ext_key;
typedef typename uset_ht::ext_value ext_value;
/// (de)constructor
unordered_set() = default;
unordered_set(const self& _x) : _h(_x._h) {}
virtual ~unordered_set() = default;
/// implement
size_type size() const { return _h.size(); }
bool empty() const { return _h.empty(); }
iterator begin() { return _h.begin(); }
iterator end() { return _h.end(); }
const_iterator cbegin() const { return _h.cbegin(); }
const_iterator cend() const { return _h.cend(); }
ireturn_type insert(const value_type& _v) { return _h.insert(_v); }
size_type erase(const key_type& _k) { return _h.erase(_k); }
size_type count(const key_type& _k) const { return _h.count(_k); }
void clear() { _h.clear(); }
iterator find(const key_type& _k) { return _h.find(_k); }
const_iterator find(const key_type& _k) const { return _h.find(_k); }
#ifdef _CONTAINER_CHECK_
int check() const { return _h.check(); }
#endif // _CONTAINER_CHECK_
/// output
template <typename _T, typename _H, typename _A>
friend std::ostream& operator<<(std::ostream& os, const unordered_set<_T, _H, _A>& _um);
// friend std::ostream& operator<<(std::ostream& os, const const_iterator& _i);
};
template <typename _Tp, typename _Hash, typename _Alloc> auto
operator<<(std::ostream& os, const unordered_set<_Tp, _Hash, _Alloc>& _um)
-> std::ostream& {
os << _um._h;
return os;
};
};
#endif // _ASP_UNORDERED_SET_HPP_