summaryrefslogtreecommitdiff
path: root/src/jit/jitstd/unordered_set.h
blob: 388e72426c7d549c07fbbad2e2b967247dcdb81b (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// ==++==
//

//

//
// ==--==

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX                                                                           XX
XX                          unordered_set<V,H,P,A>                           XX
XX                                                                           XX
XX  Derives from hashtable for most implementation. The hash key is the      XX
XX  elements themselves                                                      XX
XX                                                                           XX
XX                                                                           XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

#pragma once

#include "allocator.h"
#include "hashtable.h"

namespace jitstd
{

template <typename Value,
          typename Hash = jitstd::hash<Value>,
          typename Pred = jitstd::equal_to<Value>,
          typename Alloc = jitstd::allocator<Value>>
class unordered_set
    : public hashtable<Value, Value, Hash, Pred, Alloc>
{
public:
    typedef Value key_type;
    typedef Value value_type;
    typedef Hash hasher;
    typedef Pred key_equal;
    typedef Alloc allocator_type;
    typedef typename allocator_type::pointer pointer;             
    typedef typename allocator_type::const_pointer const_pointer;       
    typedef typename allocator_type::reference reference;
    typedef typename allocator_type::const_reference const_reference;
    typedef size_t size_type;
    typedef ptrdiff_t difference_type;
    typedef typename list<Value, Alloc>::iterator iterator;
    typedef typename list<Value, Alloc>::const_iterator const_iterator;
    typedef typename list<Value, Alloc>::iterator local_iterator;

private:
    typedef hashtable<Value, Value, Hash, Pred, Alloc> base_type;
    unordered_set();

    typedef pair<iterator, iterator> BucketEntry;
    typedef vector<BucketEntry, typename Alloc::template rebind<BucketEntry>::allocator> Buckets;
    typedef list<Value, Alloc> Elements;

public:
    explicit unordered_set(size_type,
        const allocator_type& a);

    unordered_set(size_type n,
        const hasher& hf,
        const key_equal& eq, 
        const allocator_type&);

    template<typename InputIterator> 
    unordered_set(
        InputIterator f, InputIterator l,
        size_type n,
        const hasher& hf,
        const key_equal& eq, 
        const allocator_type&);

    explicit unordered_set(const allocator_type&);

    unordered_set(const unordered_set& other);

    ~unordered_set();

    unordered_set& operator=(unordered_set const&);
};

} // end of namespace jitstd


namespace jitstd
{

template <typename Value, typename Hash, typename Pred, typename Alloc>
unordered_set<Value, Hash, Pred, Alloc>::unordered_set(
    size_type n,
    allocator_type const& allocator)
    : hashtable<Value>(n, allocator)
{
    this->rehash(n);
}

template <typename Value, typename Hash, typename Pred, typename Alloc>
unordered_set<Value, Hash, Pred, Alloc>::unordered_set(
    size_type n,
    hasher const& hf,
    key_equal const& eq,
    allocator_type const& allocator)
    : hashtable<Value>(n, hf, eq, allocator)
{
    this->rehash(n);
}

template <typename Value, typename Hash, typename Pred, typename Alloc>
template<typename InputIterator>
unordered_set<Value, Hash, Pred, Alloc>::unordered_set(
    InputIterator f, InputIterator l,
    size_type n,
    const hasher& hf,
    const key_equal& eq, 
    const allocator_type& allocator)
    : hashtable<Value>(f, l, n, hf, eq, allocator)
{
    this->rehash(n);
    insert(this->first, this->last);
}

template <typename Value, typename Hash, typename Pred, typename Alloc>
unordered_set<Value, Hash, Pred, Alloc>::unordered_set(const allocator_type& allocator)
: hashtable<Value>(allocator)
{
}

template <typename Value, typename Hash, typename Pred, typename Alloc>
unordered_set<Value, Hash, Pred, Alloc>::unordered_set(const unordered_set& other)
: hashtable<Value>(other)
{
}

template <typename Value, typename Hash, typename Pred, typename Alloc>
unordered_set<Value, Hash, Pred, Alloc>::~unordered_set()
{
}

template <typename Value, typename Hash, typename Pred, typename Alloc>
unordered_set<Value, Hash, Pred, Alloc>&
    unordered_set<Value, Hash, Pred, Alloc>::operator=(unordered_set const& other)
{
    base_type::operator=(other);
    return *this;
}

} // end of namespace jitstd.