-
Notifications
You must be signed in to change notification settings - Fork 7
/
fixed_hash_set.h
790 lines (589 loc) · 36.1 KB
/
fixed_hash_set.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// This file implements a hashSet which uses a fixed size memory pool for
// its buckets and nodes.
///////////////////////////////////////////////////////////////////////////////
#ifndef EASTL_FIXED_HASH_SET_H
#define EASTL_FIXED_HASH_SET_H
#include <eastl/hash_set.h>
#include <eastl/internal/fixed_pool.h>
EA_DISABLE_VC_WARNING(4127) // Conditional expression is constant
#if defined(EASTL_PRAGMA_ONCE_SUPPORTED)
#pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
#endif
namespace eastl
{
/// EASTL_FIXED_HASH_SET_DEFAULT_NAME
///
/// Defines a default container name in the absence of a user-provided name.
/// In the case of fixed-size containers, the allocator name always refers
/// to overflow allocations.
///
#ifndef EASTL_FIXED_HASH_SET_DEFAULT_NAME
#define EASTL_FIXED_HASH_SET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixedHashSet" // Unless the user overrides something, this is "EASTL fixedHashSet".
#endif
#ifndef EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME
#define EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " fixedHashMultiset" // Unless the user overrides something, this is "EASTL fixedHashMultiset".
#endif
/// EASTL_FIXED_HASH_SET_DEFAULT_ALLOCATOR
/// EASTL_FIXED_HASH_MULTISET_DEFAULT_ALLOCATOR
///
#ifndef EASTL_FIXED_HASH_SET_DEFAULT_ALLOCATOR
#define EASTL_FIXED_HASH_SET_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_HASH_SET_DEFAULT_NAME)
#endif
#ifndef EASTL_FIXED_HASH_MULTISET_DEFAULT_ALLOCATOR
#define EASTL_FIXED_HASH_MULTISET_DEFAULT_ALLOCATOR overflow_allocator_type(EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME)
#endif
/// fixedHashSet
///
/// Implements a hashSet with a fixed block of memory identified by the nodeCount and bucketCount
/// template parameters.
///
/// Template parameters:
/// Value The type of object the hashSet holds.
/// nodeCount The max number of objects to contain. This value must be >= 1.
/// bucketCount The number of buckets to use. This value must be >= 2.
/// bEnableOverflow Whether or not we should use the global heap if our object pool is exhausted.
/// Hash hashSet hash function. See hashSet.
/// Predicate hashSet equality testing function. See hashSet.
///
template <typename Value, size_t nodeCount, size_t bucketCount = nodeCount + 1, bool bEnableOverflow = true,
typename Hash = eastl::hash<Value>, typename Predicate = eastl::equal_to<Value>, bool bCacheHashCode = false, typename OverflowAllocator = EASTLAllocatorType>
class fixedHashSet : public hashSet<Value,
Hash,
Predicate,
fixedHashtableAllocator<
bucketCount + 1,
sizeof(typename hashSet<Value, Hash, Predicate, OverflowAllocator, bCacheHashCode>::node_type),
nodeCount,
EASTL_ALIGN_OF(typename hashSet<Value, Hash, Predicate, OverflowAllocator, bCacheHashCode>::node_type),
0,
bEnableOverflow,
OverflowAllocator>,
bCacheHashCode>
{
public:
typedef fixedHashtableAllocator<bucketCount + 1, sizeof(typename hashSet<Value, Hash, Predicate,
OverflowAllocator, bCacheHashCode>::node_type), nodeCount,
EASTL_ALIGN_OF(typename hashSet<Value, Hash, Predicate, OverflowAllocator, bCacheHashCode>::node_type),
0, bEnableOverflow, OverflowAllocator> fixedAllocator_type;
typedef typename fixedAllocator_type::overflow_allocator_type overflow_allocator_type;
typedef fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator> this_type;
typedef hashSet<Value, Hash, Predicate, fixedAllocator_type, bCacheHashCode> base_type;
typedef typename base_type::value_type value_type;
typedef typename base_type::node_type node_type;
typedef typename base_type::size_type size_type;
enum { kMaxSize = nodeCount };
protected:
using base_type::mAllocator;
node_type** mBucketBuffer[bucketCount + 1]; // '+1' because the hash table needs a null terminating bucket.
char mNodeBuffer[fixedAllocator_type::kBufferSize]; // kBufferSize will take into account alignment requirements.
public:
explicit fixedHashSet(const overflow_allocator_type& overflowAllocator);
explicit fixedHashSet(const Hash& hashFunction = Hash(),
const Predicate& predicate = Predicate());
fixedHashSet(const Hash& hashFunction,
const Predicate& predicate,
const overflow_allocator_type& overflowAllocator);
template <typename InputIterator>
fixedHashSet(InputIterator first, InputIterator last,
const Hash& hashFunction = Hash(),
const Predicate& predicate = Predicate());
fixedHashSet(const this_type& x);
fixedHashSet(this_type&& x);
fixedHashSet(this_type&& x, const overflow_allocator_type& overflowAllocator);
fixedHashSet(std::initializer_list<value_type> ilist, const overflow_allocator_type& overflowAllocator = EASTL_FIXED_HASH_SET_DEFAULT_ALLOCATOR);
this_type& operator=(const this_type& x);
this_type& operator=(std::initializer_list<value_type> ilist);
this_type& operator=(this_type&& x);
void swap(this_type& x);
void reset_lose_memory(); // This is a unilateral reset to an initially empty state. No destructors are called, no deallocation occurs.
size_type maxSize() const;
const overflow_allocator_type& getOverflowAllocator() const EASTL_NOEXCEPT;
overflow_allocator_type& getOverflowAllocator() EASTL_NOEXCEPT;
void setOverflowAllocator(const overflow_allocator_type& allocator);
}; // fixedHashSet
/// fixedHashMultiset
///
/// Implements a hashMultiset with a fixed block of memory identified by the nodeCount and bucketCount
/// template parameters.
///
/// Value The type of object the hashSet holds.
/// nodeCount The max number of objects to contain. This value must be >= 1.
/// bucketCount The number of buckets to use. This value must be >= 2.
/// bEnableOverflow Whether or not we should use the global heap if our object pool is exhausted.
/// Hash hashSet hash function. See hashSet.
/// Predicate hashSet equality testing function. See hashSet.
///
template <typename Value, size_t nodeCount, size_t bucketCount = nodeCount + 1, bool bEnableOverflow = true,
typename Hash = eastl::hash<Value>, typename Predicate = eastl::equal_to<Value>, bool bCacheHashCode = false, typename OverflowAllocator = EASTLAllocatorType>
class fixedHashMultiset : public hashMultiset<Value,
Hash,
Predicate,
fixedHashtableAllocator<
bucketCount + 1,
sizeof(typename hashMultiset<Value, Hash, Predicate, OverflowAllocator, bCacheHashCode>::node_type),
nodeCount,
EASTL_ALIGN_OF(typename hashMultiset<Value, Hash, Predicate, OverflowAllocator, bCacheHashCode>::node_type),
0,
bEnableOverflow,
OverflowAllocator>,
bCacheHashCode>
{
public:
typedef fixedHashtableAllocator<bucketCount + 1, sizeof(typename hashMultiset<Value, Hash, Predicate,
OverflowAllocator, bCacheHashCode>::node_type), nodeCount, EASTL_ALIGN_OF(typename hashMultiset<Value, Hash, Predicate,
OverflowAllocator, bCacheHashCode>::node_type), 0,
bEnableOverflow, OverflowAllocator> fixedAllocator_type;
typedef typename fixedAllocator_type::overflow_allocator_type overflow_allocator_type;
typedef hashMultiset<Value, Hash, Predicate, fixedAllocator_type, bCacheHashCode> base_type;
typedef fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator> this_type;
typedef typename base_type::value_type value_type;
typedef typename base_type::node_type node_type;
typedef typename base_type::size_type size_type;
enum { kMaxSize = nodeCount };
protected:
using base_type::mAllocator;
node_type** mBucketBuffer[bucketCount + 1]; // '+1' because the hash table needs a null terminating bucket.
char mNodeBuffer[fixedAllocator_type::kBufferSize]; // kBufferSize will take into account alignment requirements.
public:
explicit fixedHashMultiset(const overflow_allocator_type& overflowAllocator);
explicit fixedHashMultiset(const Hash& hashFunction = Hash(),
const Predicate& predicate = Predicate());
fixedHashMultiset(const Hash& hashFunction,
const Predicate& predicate,
const overflow_allocator_type& overflowAllocator);
template <typename InputIterator>
fixedHashMultiset(InputIterator first, InputIterator last,
const Hash& hashFunction = Hash(),
const Predicate& predicate = Predicate());
fixedHashMultiset(const this_type& x);
fixedHashMultiset(this_type&& x);
fixedHashMultiset(this_type&& x, const overflow_allocator_type& overflowAllocator);
fixedHashMultiset(std::initializer_list<value_type> ilist, const overflow_allocator_type& overflowAllocator = EASTL_FIXED_HASH_MULTISET_DEFAULT_ALLOCATOR);
this_type& operator=(const this_type& x);
this_type& operator=(std::initializer_list<value_type> ilist);
this_type& operator=(this_type&& x);
void swap(this_type& x);
void reset_lose_memory(); // This is a unilateral reset to an initially empty state. No destructors are called, no deallocation occurs.
size_type maxSize() const;
const overflow_allocator_type& getOverflowAllocator() const EASTL_NOEXCEPT;
overflow_allocator_type& getOverflowAllocator() EASTL_NOEXCEPT;
void setOverflowAllocator(const overflow_allocator_type& allocator);
}; // fixedHashMultiset
///////////////////////////////////////////////////////////////////////
// fixedHashSet
///////////////////////////////////////////////////////////////////////
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashSet(const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount),
Hash(), Predicate(), fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if (!bEnableOverflow)
{
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
}
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_SET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashSet(const Hash& hashFunction,
const Predicate& predicate)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount),
hashFunction, predicate, fixedAllocator_type(NULL, mBucketBuffer))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_SET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashSet(const Hash& hashFunction,
const Predicate& predicate,
const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount),
hashFunction, predicate, fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if (!bEnableOverflow)
{
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
}
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_SET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
template <typename InputIterator>
fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashSet(InputIterator first, InputIterator last,
const Hash& hashFunction,
const Predicate& predicate)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), hashFunction,
predicate, fixedAllocator_type(NULL, mBucketBuffer))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
{
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
}
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_SET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
base_type::insert(first, last);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashSet(const this_type& x)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), x.hash_function(),
x.key_eq(), fixedAllocator_type(NULL, mBucketBuffer))
{
mAllocator.copy_overflow_allocator(x.mAllocator);
#if EASTL_NAME_ENABLED
mAllocator.setName(x.mAllocator.getName());
#endif
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
mAllocator.reset(mNodeBuffer);
base_type::insert(x.begin(), x.end());
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::fixedHashSet(this_type&& x)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), x.hash_function(),
x.key_eq(), fixedAllocator_type(NULL, mBucketBuffer))
{
// This implementation is the same as above. If we could rely on using C++11 delegating constructor support then we could just call that here.
mAllocator.copy_overflow_allocator(x.mAllocator);
#if EASTL_NAME_ENABLED
mAllocator.setName(x.mAllocator.getName());
#endif
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
mAllocator.reset(mNodeBuffer);
base_type::insert(x.begin(), x.end());
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::fixedHashSet(this_type&& x, const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount),
x.hash_function(), x.key_eq(), fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
// This implementation is the same as above. If we could rely on using C++11 delegating constructor support then we could just call that here.
mAllocator.copy_overflow_allocator(x.mAllocator);
#if EASTL_NAME_ENABLED
mAllocator.setName(x.mAllocator.getName());
#endif
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
mAllocator.reset(mNodeBuffer);
base_type::insert(x.begin(), x.end());
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashSet(std::initializer_list<value_type> ilist, const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), Hash(),
Predicate(), fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_SET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
base_type::insert(ilist.begin(), ilist.end());
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
typename fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::this_type&
fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::operator=(const this_type& x)
{
base_type::operator=(x);
return *this;
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::this_type&
fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::operator=(this_type&& x)
{
operator=(x);
return *this;
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::this_type&
fixedHashSet<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::operator=(std::initializer_list<value_type> ilist)
{
base_type::clear();
base_type::insert(ilist.begin(), ilist.end());
return *this;
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline void fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
swap(this_type& x)
{
// We must do a brute-force swap, because fixed containers cannot share memory allocations.
// Note that we create a temp value on the stack. This approach may fail if the size of the
// container is too large. We have a rule against allocating memory from the heap, and so
// if the user wants to swap two large objects of this class, the user will currently need
// to implement it manually. To consider: add code to allocate a temporary buffer if the
// size of the container is too large for the stack.
EASTL_ASSERT(sizeof(x) < EASTL_MAX_STACK_USAGE); // It is dangerous to try to create objects that are too big for the stack.
const this_type temp(*this); // Can't call eastl::swap because that would
*this = x; // itself call this member swap function.
x = temp;
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
void fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
reset_lose_memory()
{
base_type::reset_lose_memory();
base_type::getAllocator().reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::size_type
fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::maxSize() const
{
return kMaxSize;
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline const typename fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::overflow_allocator_type&
fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::getOverflowAllocator() const EASTL_NOEXCEPT
{
return mAllocator.getOverflowAllocator();
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::overflow_allocator_type&
fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::getOverflowAllocator() EASTL_NOEXCEPT
{
return mAllocator.getOverflowAllocator();
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline void fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
setOverflowAllocator(const overflow_allocator_type& allocator)
{
mAllocator.setOverflowAllocator(allocator);
}
///////////////////////////////////////////////////////////////////////
// global operators
///////////////////////////////////////////////////////////////////////
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode>
inline void swap(fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode>& a,
fixedHashSet<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode>& b)
{
a.swap(b);
}
///////////////////////////////////////////////////////////////////////
// fixedHashMultiset
///////////////////////////////////////////////////////////////////////
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashMultiset(const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), Hash(),
Predicate(), fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashMultiset(const Hash& hashFunction,
const Predicate& predicate)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), hashFunction,
predicate, fixedAllocator_type(NULL, mBucketBuffer))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashMultiset(const Hash& hashFunction,
const Predicate& predicate,
const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), hashFunction,
predicate, fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
template <typename InputIterator>
inline fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashMultiset(InputIterator first, InputIterator last,
const Hash& hashFunction,
const Predicate& predicate)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), hashFunction,
predicate, fixedAllocator_type(NULL, mBucketBuffer))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
base_type::insert(first, last);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashMultiset(const this_type& x)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), x.hash_function(),
x.key_eq(), fixedAllocator_type(NULL, mBucketBuffer))
{
mAllocator.copy_overflow_allocator(x.mAllocator);
#if EASTL_NAME_ENABLED
mAllocator.setName(x.mAllocator.getName());
#endif
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
mAllocator.reset(mNodeBuffer);
base_type::insert(x.begin(), x.end());
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::fixedHashMultiset(this_type&& x)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), x.hash_function(),
x.key_eq(), fixedAllocator_type(NULL, mBucketBuffer))
{
// This implementation is the same as above. If we could rely on using C++11 delegating constructor support then we could just call that here.
mAllocator.copy_overflow_allocator(x.mAllocator);
#if EASTL_NAME_ENABLED
mAllocator.setName(x.mAllocator.getName());
#endif
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
mAllocator.reset(mNodeBuffer);
base_type::insert(x.begin(), x.end());
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::fixedHashMultiset(this_type&& x, const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount),
x.hash_function(), x.key_eq(), fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
// This implementation is the same as above. If we could rely on using C++11 delegating constructor support then we could just call that here.
mAllocator.copy_overflow_allocator(x.mAllocator);
#if EASTL_NAME_ENABLED
mAllocator.setName(x.mAllocator.getName());
#endif
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
mAllocator.reset(mNodeBuffer);
base_type::insert(x.begin(), x.end());
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
fixedHashMultiset(std::initializer_list<value_type> ilist, const overflow_allocator_type& overflowAllocator)
: base_type(prime_rehash_policy::GetPrevBucketCountOnly(bucketCount), Hash(),
Predicate(), fixedAllocator_type(NULL, mBucketBuffer, overflowAllocator))
{
EASTL_CT_ASSERT((nodeCount >= 1) && (bucketCount >= 2));
if(!bEnableOverflow)
base_type::set_max_load_factor(10000.f); // Set it so that we will never resize.
#if EASTL_NAME_ENABLED
mAllocator.setName(EASTL_FIXED_HASH_MULTISET_DEFAULT_NAME);
#endif
mAllocator.reset(mNodeBuffer);
base_type::insert(ilist.begin(), ilist.end());
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::this_type&
fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::operator=(const this_type& x)
{
base_type::operator=(x);
return *this;
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::this_type&
fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::operator=(this_type&& x)
{
base_type::operator=(x);
return *this;
}
template <typename Key, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::this_type&
fixedHashMultiset<Key, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::operator=(std::initializer_list<value_type> ilist)
{
base_type::clear();
base_type::insert(ilist.begin(), ilist.end());
return *this;
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline void fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
swap(this_type& x)
{
// Fixed containers use a special swap that can deal with excessively large buffers.
eastl::fixedSwap(*this, x);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline void fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
reset_lose_memory()
{
base_type::reset_lose_memory();
base_type::getAllocator().reset(mNodeBuffer);
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::size_type
fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::maxSize() const
{
return kMaxSize;
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline const typename fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::overflow_allocator_type&
fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::getOverflowAllocator() const EASTL_NOEXCEPT
{
return mAllocator.getOverflowAllocator();
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline typename fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::overflow_allocator_type&
fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::getOverflowAllocator() EASTL_NOEXCEPT
{
return mAllocator.getOverflowAllocator();
}
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode, typename OverflowAllocator>
inline void fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode, OverflowAllocator>::
setOverflowAllocator(const overflow_allocator_type& allocator)
{
mAllocator.setOverflowAllocator(allocator);
}
///////////////////////////////////////////////////////////////////////
// global operators
///////////////////////////////////////////////////////////////////////
template <typename Value, size_t nodeCount, size_t bucketCount, bool bEnableOverflow, typename Hash, typename Predicate, bool bCacheHashCode>
inline void swap(fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode>& a,
fixedHashMultiset<Value, nodeCount, bucketCount, bEnableOverflow, Hash, Predicate, bCacheHashCode>& b)
{
// Fixed containers use a special swap that can deal with excessively large buffers.
eastl::fixedSwap(a, b);
}
} // namespace eastl
EA_RESTORE_VC_WARNING()
#endif // Header include guard