1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | // ==++== |
6 | // |
7 | |
8 | // |
9 | |
10 | // |
11 | // ==--== |
12 | |
13 | /*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
14 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
15 | XX XX |
16 | XX unordered_set<V,H,P,A> XX |
17 | XX XX |
18 | XX Derives from hashtable for most implementation. The hash key is the XX |
19 | XX elements themselves XX |
20 | XX XX |
21 | XX XX |
22 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
23 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "allocator.h" |
29 | #include "hashtable.h" |
30 | |
31 | namespace jitstd |
32 | { |
33 | |
34 | template <typename Value, |
35 | typename Hash = jitstd::hash<Value>, |
36 | typename Pred = jitstd::equal_to<Value>, |
37 | typename Alloc = jitstd::allocator<Value>> |
38 | class unordered_set |
39 | : public hashtable<Value, Value, Hash, Pred, Alloc> |
40 | { |
41 | public: |
42 | typedef Value key_type; |
43 | typedef Value value_type; |
44 | typedef Hash hasher; |
45 | typedef Pred key_equal; |
46 | typedef Alloc allocator_type; |
47 | typedef typename allocator_type::pointer pointer; |
48 | typedef typename allocator_type::const_pointer const_pointer; |
49 | typedef typename allocator_type::reference reference; |
50 | typedef typename allocator_type::const_reference const_reference; |
51 | typedef size_t size_type; |
52 | typedef ptrdiff_t difference_type; |
53 | typedef typename list<Value, Alloc>::iterator iterator; |
54 | typedef typename list<Value, Alloc>::const_iterator const_iterator; |
55 | typedef typename list<Value, Alloc>::iterator local_iterator; |
56 | |
57 | private: |
58 | typedef hashtable<Value, Value, Hash, Pred, Alloc> base_type; |
59 | unordered_set(); |
60 | |
61 | typedef pair<iterator, iterator> BucketEntry; |
62 | typedef vector<BucketEntry, typename Alloc::template rebind<BucketEntry>::allocator> Buckets; |
63 | typedef list<Value, Alloc> Elements; |
64 | |
65 | public: |
66 | explicit unordered_set(size_type, |
67 | const allocator_type& a); |
68 | |
69 | unordered_set(size_type n, |
70 | const hasher& hf, |
71 | const key_equal& eq, |
72 | const allocator_type&); |
73 | |
74 | template<typename InputIterator> |
75 | unordered_set( |
76 | InputIterator f, InputIterator l, |
77 | size_type n, |
78 | const hasher& hf, |
79 | const key_equal& eq, |
80 | const allocator_type&); |
81 | |
82 | explicit unordered_set(const allocator_type&); |
83 | |
84 | unordered_set(const unordered_set& other); |
85 | |
86 | ~unordered_set(); |
87 | |
88 | unordered_set& operator=(unordered_set const&); |
89 | }; |
90 | |
91 | } // end of namespace jitstd |
92 | |
93 | |
94 | namespace jitstd |
95 | { |
96 | |
97 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
98 | unordered_set<Value, Hash, Pred, Alloc>::unordered_set( |
99 | size_type n, |
100 | allocator_type const& allocator) |
101 | : hashtable<Value>(n, allocator) |
102 | { |
103 | this->rehash(n); |
104 | } |
105 | |
106 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
107 | unordered_set<Value, Hash, Pred, Alloc>::unordered_set( |
108 | size_type n, |
109 | hasher const& hf, |
110 | key_equal const& eq, |
111 | allocator_type const& allocator) |
112 | : hashtable<Value>(n, hf, eq, allocator) |
113 | { |
114 | this->rehash(n); |
115 | } |
116 | |
117 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
118 | template<typename InputIterator> |
119 | unordered_set<Value, Hash, Pred, Alloc>::unordered_set( |
120 | InputIterator f, InputIterator l, |
121 | size_type n, |
122 | const hasher& hf, |
123 | const key_equal& eq, |
124 | const allocator_type& allocator) |
125 | : hashtable<Value>(f, l, n, hf, eq, allocator) |
126 | { |
127 | this->rehash(n); |
128 | insert(this->first, this->last); |
129 | } |
130 | |
131 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
132 | unordered_set<Value, Hash, Pred, Alloc>::unordered_set(const allocator_type& allocator) |
133 | : hashtable<Value>(allocator) |
134 | { |
135 | } |
136 | |
137 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
138 | unordered_set<Value, Hash, Pred, Alloc>::unordered_set(const unordered_set& other) |
139 | : hashtable<Value>(other) |
140 | { |
141 | } |
142 | |
143 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
144 | unordered_set<Value, Hash, Pred, Alloc>::~unordered_set() |
145 | { |
146 | } |
147 | |
148 | template <typename Value, typename Hash, typename Pred, typename Alloc> |
149 | unordered_set<Value, Hash, Pred, Alloc>& |
150 | unordered_set<Value, Hash, Pred, Alloc>::operator=(unordered_set const& other) |
151 | { |
152 | base_type::operator=(other); |
153 | return *this; |
154 | } |
155 | |
156 | } // end of namespace jitstd. |
157 | |