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
14XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
15XX XX
16XX unordered_set<V,H,P,A> XX
17XX XX
18XX Derives from hashtable for most implementation. The hash key is the XX
19XX elements themselves XX
20XX XX
21XX XX
22XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
23XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
24*/
25
26#pragma once
27
28#include "allocator.h"
29#include "hashtable.h"
30
31namespace jitstd
32{
33
34template <typename Value,
35 typename Hash = jitstd::hash<Value>,
36 typename Pred = jitstd::equal_to<Value>,
37 typename Alloc = jitstd::allocator<Value>>
38class unordered_set
39 : public hashtable<Value, Value, Hash, Pred, Alloc>
40{
41public:
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
57private:
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
65public:
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
94namespace jitstd
95{
96
97template <typename Value, typename Hash, typename Pred, typename Alloc>
98unordered_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
106template <typename Value, typename Hash, typename Pred, typename Alloc>
107unordered_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
117template <typename Value, typename Hash, typename Pred, typename Alloc>
118template<typename InputIterator>
119unordered_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
131template <typename Value, typename Hash, typename Pred, typename Alloc>
132unordered_set<Value, Hash, Pred, Alloc>::unordered_set(const allocator_type& allocator)
133: hashtable<Value>(allocator)
134{
135}
136
137template <typename Value, typename Hash, typename Pred, typename Alloc>
138unordered_set<Value, Hash, Pred, Alloc>::unordered_set(const unordered_set& other)
139: hashtable<Value>(other)
140{
141}
142
143template <typename Value, typename Hash, typename Pred, typename Alloc>
144unordered_set<Value, Hash, Pred, Alloc>::~unordered_set()
145{
146}
147
148template <typename Value, typename Hash, typename Pred, typename Alloc>
149unordered_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