1
- #ifndef LIBCUCKOO_BUCKET_CONTAINER_H
2
- #define LIBCUCKOO_BUCKET_CONTAINER_H
1
+ #ifndef BUCKET_CONTAINER_H
2
+ #define BUCKET_CONTAINER_H
3
3
4
4
#include < array>
5
5
#include < atomic>
12
12
13
13
#include " cuckoohash_util.hh"
14
14
15
+ namespace libcuckoo {
16
+
15
17
/* *
16
- * libcuckoo_bucket_container manages storage of key-value pairs for the table.
18
+ * bucket_container manages storage of key-value pairs for the table.
17
19
* It stores the items inline in uninitialized memory, and keeps track of which
18
20
* slots have live data and which do not. It also stores a partial hash for
19
21
* each live key. It is sized by powers of two.
26
28
*/
27
29
template <class Key , class T , class Allocator , class Partial ,
28
30
std::size_t SLOT_PER_BUCKET>
29
- class libcuckoo_bucket_container {
31
+ class bucket_container {
30
32
public:
31
33
using key_type = Key;
32
34
using mapped_type = T;
@@ -84,7 +86,7 @@ public:
84
86
bool &occupied (size_type ind) { return occupied_[ind]; }
85
87
86
88
private:
87
- friend class libcuckoo_bucket_container ;
89
+ friend class bucket_container ;
88
90
89
91
using storage_value_type = std::pair<Key, T>;
90
92
@@ -105,48 +107,48 @@ public:
105
107
std::array<bool , SLOT_PER_BUCKET> occupied_;
106
108
};
107
109
108
- libcuckoo_bucket_container (size_type hp, const allocator_type &allocator)
110
+ bucket_container (size_type hp, const allocator_type &allocator)
109
111
: allocator_(allocator), bucket_allocator_(allocator), hashpower_(hp),
110
112
buckets_ (bucket_allocator_.allocate(size())) {
111
113
// The bucket default constructor is nothrow, so we don't have to
112
114
// worry about dealing with exceptions when constructing all the
113
115
// elements.
114
116
static_assert (std::is_nothrow_constructible<bucket>::value,
115
- " libcuckoo_bucket_container requires bucket to be nothrow "
117
+ " bucket_container requires bucket to be nothrow "
116
118
" constructible" );
117
119
for (size_type i = 0 ; i < size (); ++i) {
118
120
traits_::construct (allocator_, &buckets_[i]);
119
121
}
120
122
}
121
123
122
- ~libcuckoo_bucket_container () noexcept { destroy_buckets (); }
124
+ ~bucket_container () noexcept { destroy_buckets (); }
123
125
124
- libcuckoo_bucket_container (const libcuckoo_bucket_container &bc)
126
+ bucket_container (const bucket_container &bc)
125
127
: allocator_(
126
128
traits_::select_on_container_copy_construction (bc.allocator_)),
127
129
bucket_allocator_(allocator_), hashpower_(bc.hashpower()),
128
130
buckets_(transfer(bc.hashpower(), bc, std::false_type())) {}
129
131
130
- libcuckoo_bucket_container (const libcuckoo_bucket_container &bc,
132
+ bucket_container (const bucket_container &bc,
131
133
const allocator_type &a)
132
134
: allocator_(a), bucket_allocator_(allocator_),
133
135
hashpower_(bc.hashpower()),
134
136
buckets_(transfer(bc.hashpower(), bc, std::false_type())) {}
135
137
136
- libcuckoo_bucket_container (libcuckoo_bucket_container &&bc)
138
+ bucket_container (bucket_container &&bc)
137
139
: allocator_(std::move(bc.allocator_)), bucket_allocator_(allocator_),
138
140
hashpower_(bc.hashpower()), buckets_(std::move(bc.buckets_)) {
139
141
// De-activate the other buckets container
140
142
bc.buckets_ = nullptr ;
141
143
}
142
144
143
- libcuckoo_bucket_container (libcuckoo_bucket_container &&bc,
145
+ bucket_container (bucket_container &&bc,
144
146
const allocator_type &a)
145
147
: allocator_(a), bucket_allocator_(allocator_) {
146
148
move_assign (bc, std::false_type ());
147
149
}
148
150
149
- libcuckoo_bucket_container &operator =(const libcuckoo_bucket_container &bc) {
151
+ bucket_container &operator =(const bucket_container &bc) {
150
152
destroy_buckets ();
151
153
copy_allocator (allocator_, bc.allocator_ ,
152
154
typename traits_::propagate_on_container_copy_assignment ());
@@ -156,13 +158,13 @@ public:
156
158
return *this ;
157
159
}
158
160
159
- libcuckoo_bucket_container &operator =(libcuckoo_bucket_container &&bc) {
161
+ bucket_container &operator =(bucket_container &&bc) {
160
162
destroy_buckets ();
161
163
move_assign (bc, typename traits_::propagate_on_container_move_assignment ());
162
164
return *this ;
163
165
}
164
166
165
- void swap (libcuckoo_bucket_container &bc) noexcept {
167
+ void swap (bucket_container &bc) noexcept {
166
168
swap_allocator (allocator_, bc.allocator_ ,
167
169
typename traits_::propagate_on_container_swap ());
168
170
swap_allocator (bucket_allocator_, bc.bucket_allocator_ ,
@@ -223,7 +225,7 @@ public:
223
225
static_assert (
224
226
std::is_nothrow_destructible<key_type>::value &&
225
227
std::is_nothrow_destructible<mapped_type>::value,
226
- " libcuckoo_bucket_container requires key and value to be nothrow "
228
+ " bucket_container requires key and value to be nothrow "
227
229
" destructible" );
228
230
for (size_type i = 0 ; i < size (); ++i) {
229
231
bucket &b = buckets_[i];
@@ -263,15 +265,15 @@ private:
263
265
template <typename A> void swap_allocator (A &, A &, std::false_type) {}
264
266
265
267
// true here means the bucket allocator should be propagated
266
- void move_assign (libcuckoo_bucket_container &src, std::true_type) {
268
+ void move_assign (bucket_container &src, std::true_type) {
267
269
allocator_ = std::move (src.allocator_ );
268
270
bucket_allocator_ = allocator_;
269
271
hashpower (src.hashpower ());
270
272
buckets_ = src.buckets_ ;
271
273
src.buckets_ = nullptr ;
272
274
}
273
275
274
- void move_assign (libcuckoo_bucket_container &src, std::false_type) {
276
+ void move_assign (bucket_container &src, std::false_type) {
275
277
hashpower (src.hashpower ());
276
278
if (allocator_ == src.allocator_ ) {
277
279
buckets_ = src.buckets_ ;
@@ -289,7 +291,7 @@ private:
289
291
// worry about dealing with exceptions when constructing all the
290
292
// elements.
291
293
static_assert (std::is_nothrow_destructible<bucket>::value,
292
- " libcuckoo_bucket_container requires bucket to be nothrow "
294
+ " bucket_container requires bucket to be nothrow "
293
295
" destructible" );
294
296
clear ();
295
297
for (size_type i = 0 ; i < size (); ++i) {
@@ -315,11 +317,11 @@ private:
315
317
template <bool B>
316
318
bucket_pointer transfer (
317
319
size_type dst_hp,
318
- typename std::conditional<B, libcuckoo_bucket_container &,
319
- const libcuckoo_bucket_container &>::type src,
320
+ typename std::conditional<B, bucket_container &,
321
+ const bucket_container &>::type src,
320
322
std::integral_constant<bool , B> move) {
321
323
assert (dst_hp >= src.hashpower ());
322
- libcuckoo_bucket_container dst (dst_hp, get_allocator ());
324
+ bucket_container dst (dst_hp, get_allocator ());
323
325
// Move/copy all occupied slots of the source buckets
324
326
for (size_t i = 0 ; i < src.size (); ++i) {
325
327
for (size_t j = 0 ; j < SLOT_PER_BUCKET; ++j) {
@@ -359,7 +361,7 @@ private:
359
361
std::is_trivial<ThisT>::value,
360
362
std::ostream &>::type
361
363
operator <<(std::ostream &os,
362
- const libcuckoo_bucket_container <ThisKey, ThisT, Allocator,
364
+ const bucket_container <ThisKey, ThisT, Allocator,
363
365
Partial, SLOT_PER_BUCKET> &bc) {
364
366
size_type hp = bc.hashpower ();
365
367
os.write (reinterpret_cast <const char *>(&hp), sizeof (size_type));
@@ -373,16 +375,18 @@ private:
373
375
std::is_trivial<ThisT>::value,
374
376
std::istream &>::type
375
377
operator >>(std::istream &is,
376
- libcuckoo_bucket_container <ThisKey, ThisT, Allocator,
378
+ bucket_container <ThisKey, ThisT, Allocator,
377
379
Partial, SLOT_PER_BUCKET> &bc) {
378
380
size_type hp;
379
381
is.read (reinterpret_cast <char *>(&hp), sizeof (size_type));
380
- libcuckoo_bucket_container new_bc (hp, bc.get_allocator ());
382
+ bucket_container new_bc (hp, bc.get_allocator ());
381
383
is.read (reinterpret_cast <char *>(new_bc.buckets_ ),
382
384
new_bc.size () * sizeof (bucket));
383
385
bc.swap (new_bc);
384
386
return is;
385
387
}
386
388
};
387
389
388
- #endif // LIBCUCKOO_BUCKET_CONTAINER_H
390
+ } // namespace libcuckoo
391
+
392
+ #endif // BUCKET_CONTAINER_H
0 commit comments