2
* Copyright 2006-2008 The FLWOR Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#ifndef ZORBA_UNORDERED_SET_H
19
#define ZORBA_UNORDERED_SET_H
21
#include <zorba/config.h>
23
#ifdef ZORBA_HAVE_UNORDERED_SET
24
# include <unordered_set> /* use the implementation version */
28
#include "util/hash/hash.h"
29
#include "util/hash/hashtable.h"
30
#include "util/hash/rehash_policy.h"
31
#ifndef ZORBA_UNORDERED_SET_REHASH_POLICY
32
# define ZORBA_UNORDERED_SET_REHASH_POLICY zorba::ztd::prime_rehash_policy
33
#endif /* ZORBA_UNORDERED_SET_REHASH_POLICY */
39
///////////////////////////////////////////////////////////////////////////////
42
* This is an implementation of the C++ %unordered_set class, but for C++98.
43
* As such, it lacks member functions that use r-value references.
45
* @tparam KeyType They set's key type.
46
* @tparam KeyHash The unary_function to use for generating hash codes.
47
* @tparam KeyEqual The binary_function to use to test for value equality.
48
* @tparam Allocator The allocator to use.
52
class KeyHash = std::hash<KeyType>,
53
class KeyEqual = std::equal_to<KeyType>,
54
class Allocator = std::allocator<KeyType>
57
public zorba::ztd::hashtable<
58
KeyType, KeyType, zorba::ztd::identity<KeyType>,
59
KeyHash, KeyEqual, Allocator, ZORBA_UNORDERED_SET_REHASH_POLICY
62
typedef zorba::ztd::hashtable<
63
KeyType, KeyType, zorba::ztd::identity<KeyType>,
64
KeyHash, KeyEqual, Allocator, ZORBA_UNORDERED_SET_REHASH_POLICY
67
typedef typename base_type::rehash_policy_type rehash_policy_type;
69
typedef typename base_type::key_type key_type;
70
typedef typename base_type::value_type value_type;
71
typedef typename base_type::hasher hasher;
72
typedef typename base_type::key_equal key_equal;
73
typedef typename base_type::allocator_type allocator_type;
75
typedef typename base_type::pointer pointer;
76
typedef typename base_type::const_pointer const_pointer;
77
typedef typename base_type::reference reference;
78
typedef typename base_type::const_reference const_reference;
80
typedef typename base_type::size_type size_type;
81
typedef typename base_type::difference_type difference_type;
83
typedef typename base_type::local_iterator local_iterator;
84
typedef typename base_type::const_local_iterator const_local_iterator;
85
typedef typename base_type::iterator iterator;
86
typedef typename base_type::const_iterator const_iterator;
89
* Constructs an %unordered_set.
91
* @param bucket_count The initial number of buckets.
92
* @param hash The unary_function to use for generating hash codes.
93
* @param equal The binary_function to use to test for key equality.
94
* @param alloc The allocator to use.
96
explicit unordered_set(
97
size_type bucket_count = rehash_policy_type::default_bucket_count,
98
hasher const &hash = hasher(),
99
key_equal const &equal = key_equal(),
100
allocator_type const &alloc = allocator_type()
102
base_type( bucket_count, hash, equal, alloc )
107
* Constructs an %unordered_set.
109
* @param alloc The allocator to use.
111
explicit unordered_set( allocator_type const &alloc ) : base_type( alloc ) {
115
* Copy-constructs an %unordered_set.
117
* @param that The %unordered_set to copy from.
119
unordered_set( unordered_set const &that ) : base_type( that ) {
125
* @param that The %unordered_set to assign from.
127
unordered_set& operator=( unordered_set const &that ) {
128
base_type::operator=( that );
133
///////////////////////////////////////////////////////////////////////////////
136
* Global %swap operator for unordered_set.
138
* @param a The first unordered_set.
139
* @param b The second unordered_set.
141
template<typename V,class H,class E,class A> inline
142
void swap( unordered_set<V,H,E,A> &a, unordered_set<V,H,E,A> &b ) {
146
///////////////////////////////////////////////////////////////////////////////
150
#endif /* ZORBA_HAVE_UNORDERED_SET */
151
#endif /* ZORBA_UNORDERED_SET_H */
152
/* vim:set et ts=2 sw=2: */