aboutsummaryrefslogtreecommitdiff
path: root/EASTL/test/source/TestIntrusiveHash.cpp
blob: 4fd8215c9548f4624af79031275f99c20041e99e (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
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
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////


#include "EASTLTest.h"
#include <EASTL/internal/intrusive_hashtable.h>
#include <EASTL/intrusive_hash_set.h>
#include <EASTL/intrusive_hash_map.h>
#include <EABase/eabase.h>



using namespace eastl;


namespace
{
	struct SetWidget : public intrusive_hash_node
	{
		SetWidget(int x = 0)
			: mX(x) { }
		int mX;
	};

	inline bool operator==(const SetWidget& a, const SetWidget& b)
		{ return a.mX == b.mX; }

	struct SWHash
	{
		size_t operator()(const SetWidget& sw) const
		{
			return (size_t)sw.mX;
		}
	};

	struct SetWidgetComparable // Exists for the sole purpose of testing the find_as function.
	{
		SetWidgetComparable(int x = 0)
			: mX(x) { }
		int mX;
	};

	struct SWCHash
	{
		size_t operator()(const SetWidgetComparable& swc) const
		{
			return (size_t)swc.mX;
		}
	};

	bool operator==(const SetWidget& a, const SetWidgetComparable& b)
		{ return a.mX == b.mX; }



	struct MapWidget : public intrusive_hash_node_key<int>
	{
		MapWidget(int x = 0)
			: mX(x) { }
		int mX;
	};

	inline bool operator==(const MapWidget& a, const MapWidget& b)
		{ return a.mX == b.mX; }

	//struct MapWidgetComparable // Exists for the sole purpose of testing the find_as function.
	//{
	//    MapWidgetComparable(int x = 0)
	//        : mX(x) { }
	//    int mX;
	//};
	//
	//bool operator==(const SetWidget& a, const MapWidgetComparable& b)
	//    { return a.mX == b.mX; }




	// IHWidget
	//
	// Implements the intrusive node data directly instead of inheriting from intrusive_hash_node.
	//
	struct IHWidget
	{
		IHWidget(int x = 0)
			: mX(x) { }

		int         mX;
		IHWidget*   mpNext;
		typedef int key_type;
		int         mKey;

	};

	inline bool operator==(const IHWidget& a, const IHWidget& b)
		{ return a.mX == b.mX; }

	struct IHWHash
	{
		size_t operator()(const IHWidget& ihw) const
		{
			return (size_t)ihw.mX;
		}
	};

} // namespace




// Template instantations.
// These tell the compiler to compile all the functions for the given class.
//template class intrusive_hash_set<SetWidget>;
//template class intrusive_hash_map<MapWidget>;


template class eastl::intrusive_hashtable<SetWidget, SetWidget, SWHash, eastl::equal_to<SetWidget>, 37, true, true>;
template class eastl::intrusive_hashtable<int, MapWidget, eastl::hash<int>, eastl::equal_to<int>, 37, false, true>;

template class eastl::intrusive_hash_set<SetWidget, 37, SWHash>;
template class eastl::intrusive_hash_multiset<SetWidget, 37, SWHash>;

template class eastl::intrusive_hash_map<int, MapWidget, 37>;
template class eastl::intrusive_hash_multimap<int, MapWidget, 37>;

template class eastl::intrusive_hash_set<IHWidget, 37, IHWHash>;
template class eastl::intrusive_hash_multiset<IHWidget, 37, IHWHash>;

template class eastl::intrusive_hash_map<int, IHWidget, 37, IHWHash>;
template class eastl::intrusive_hash_multimap<int, IHWidget, 37, IHWHash>;





int TestIntrusiveHash()
{
	int nErrorCount = 0;

	{
		SetWidget sw1, sw2;
		VERIFY(sw1 == sw2);

		MapWidget mw1, mw2;
		VERIFY(mw1 == mw2);

		IHWidget iw1, iw2;
		VERIFY(iw1 == iw2);

		IHWHash ih1;
		VERIFY(ih1.operator()(iw1) == ih1.operator()(iw2));
	}

	{
		// Test intrusive_hash_set

		const size_t kBucketCount = 37;
		typedef intrusive_hash_set<SetWidget, kBucketCount, SWHash> IHM_SW;

		const size_t kArraySize = 100;
		SetWidget swArray[kArraySize];

		int nExpectedKeySum = 0; // We use this as a checksum in order to do validity checks below.

		for(size_t i = 0; i < kArraySize; i++)
		{
			swArray[i].mX    = (int)i;
			nExpectedKeySum += (int)i;
		}


		// const key_equal& key_eq() const;
		// key_equal&       key_eq();
		IHM_SW       ih;
		const IHM_SW ihc;

		const IHM_SW::key_equal& ke = ihc.key_eq();
		ih.key_eq() = ke;


		// intrusive_hashtable(const Hash&, const Equal&);
		// void swap(this_type& x);
		// size_type size() const;
		// bool empty() const;
		// size_type bucket_count() const;
		// size_type bucket_size(size_type n) const;
		// float load_factor() const;
		// void clear();
		// bool validate() const;

		IHM_SW ihmSW1;
		IHM_SW ihmSW2;

		VERIFY(ihmSW1.size() == 0);
		VERIFY(ihmSW1.empty());
		VERIFY(ihmSW1.validate());
		VERIFY(ihmSW2.validate());

		ihmSW1.swap(ihmSW2);

		VERIFY(ihmSW1.validate());
		VERIFY(ihmSW2.validate());
		VERIFY(ihmSW2.bucket_count() == kBucketCount);
		VERIFY(ihmSW2.bucket_size(0) == 0);
		VERIFY(ihmSW2.bucket_size(kBucketCount - 1) == 0);
		VERIFY(ihmSW1.load_factor() == 0.f);
		VERIFY(ihmSW2.load_factor() == 0.f);

		ihmSW1.clear();
		VERIFY(ihmSW1.validate());
		VERIFY(ihmSW1.begin() == ihmSW1.end());


		// void insert(InputIterator first, InputIterator last);
		// insert_return_type insert(value_type& value);
		// void swap(this_type& x);
		// void clear();

		ihmSW1.clear();
		ihmSW1.insert(swArray, swArray + (kArraySize - 10));
		for(int i = 0; i < 10; i++) // insert the remaining elements via the other insert function.
		{
			pair<IHM_SW::iterator, bool> result = ihmSW1.insert(swArray[(kArraySize - 10) + i]);
			VERIFY(result.second == true);
		}

		VERIFY(ihmSW1.size() == kArraySize);
		VERIFY(ihmSW1.validate());

		for(size_t i = 0; i < kArraySize; i++)
		{
			// Try to re-insert the elements. All insertions should fail.
			pair<IHM_SW::iterator, bool> result = ihmSW1.insert(swArray[i]);
			VERIFY(result.second == false);
		}

		VERIFY(ihmSW1.size() == kArraySize);
		VERIFY(!ihmSW1.empty());
		VERIFY(ihmSW1.validate());

		ihmSW2.clear();
		ihmSW1.swap(ihmSW2);


		// size_type size() const;
		// bool empty() const;
		// size_type count(const key_type& k) const;
		// size_type bucket_size(size_type n) const;
		// float load_factor() const;
		// size_type bucket(const key_type& k) const

		VERIFY(ihmSW1.validate());
		VERIFY(ihmSW2.validate());
		VERIFY(ihmSW1.size() == 0);
		VERIFY(ihmSW1.empty());
		VERIFY(ihmSW2.size() == kArraySize);
		VERIFY(!ihmSW2.empty());
		VERIFY(ihmSW1.load_factor() == 0.f);
		VERIFY(ihmSW2.load_factor() > 2.f);
		VERIFY(ihmSW1.count(0) == 0);
		VERIFY(ihmSW1.count(999999) == 0);
		VERIFY(ihmSW2.count(0) == 1);
		VERIFY(ihmSW2.count(999999) == 0);
		VERIFY(ihmSW2.bucket_size(0) == 3);     // We just happen to know this should be so based on the distribution.
		VERIFY(ihmSW2.bucket(13)    == (13    % kBucketCount)); // We know this is so because our hash function simply returns n.
		VERIFY(ihmSW2.bucket(10000) == (10000 % kBucketCount)); // We know this is so because our hash function simply returns n.
   

		// iterator begin();
		// const_iterator begin() const;

		ihmSW1.swap(ihmSW2);
		int nSum = 0; 

		for(IHM_SW::iterator it = ihmSW1.begin(); it != ihmSW1.end(); ++it)
		{
			const SetWidget& sw = *it; // Recall that set iterators are const_iterators.

			nSum += sw.mX;

			const int iresult = ihmSW1.validate_iterator(it);
			VERIFY(iresult == (isf_valid | isf_current | isf_can_dereference));

			IHM_SW::iterator itf = ihmSW1.find(sw.mX);
			VERIFY(itf == it);
		}

		VERIFY(nSum == nExpectedKeySum);


		// iterator end();
		// const_iterator end() const;

		const IHM_SW& ihmSW1Const = ihmSW1;

		for(IHM_SW::const_iterator itc = ihmSW1Const.begin(); itc != ihmSW1Const.end(); ++itc)
		{
			const SetWidget& sw = *itc;

			IHM_SW::const_iterator itf = ihmSW1.find(sw.mX);
			VERIFY(itf == itc);
		}


		// local_iterator begin(size_type n)
		// local_iterator end(size_type)

		for(IHM_SW::local_iterator itl = ihmSW1.begin(5); itl != ihmSW1.end(5); ++itl)
		{
			const SetWidget& sw = *itl; // Recall that set iterators are const_iterators.

			VERIFY((sw.mX % kBucketCount) == 5);
		}


		// const_local_iterator begin(size_type n) const
		// const_local_iterator end(size_type) const

		for(IHM_SW::const_local_iterator itlc = ihmSW1Const.begin(5); itlc != ihmSW1Const.end(5); ++itlc)
		{
			const SetWidget& sw = *itlc;

			VERIFY((sw.mX % kBucketCount) == 5);
		}


		// iterator       find(const key_type& k);
		// const_iterator find(const key_type& k) const;

		IHM_SW::iterator itf = ihmSW1.find(SetWidget(99999));
		VERIFY(itf == ihmSW1.end());

		IHM_SW::const_iterator itfc = ihmSW1Const.find(SetWidget(99999));
		VERIFY(itfc == ihmSW1Const.end());


		// iterator       find_as(const U& u);
		// const_iterator find_as(const U& u) const;

		//itf = ihmSW1.find_as(SetWidget(7)); // Can't work unless there was a default eastl::hash function for SetWidget.
		//VERIFY(itf->mX == 7);

		//itfc = ihmSW1Const.find_as(SetWidget(7));
		//VERIFY(itfc->mX == 7);


		// iterator       find_as(const U& u, UHash uhash, BinaryPredicate predicate);
		// const_iterator find_as(const U& u, UHash uhash, BinaryPredicate predicate) const;

		itf = ihmSW1.find_as(SetWidgetComparable(7), SWCHash(), eastl::equal_to_2<SetWidget, SetWidgetComparable>());
		VERIFY(itf->mX == 7);

		itfc = ihmSW1Const.find_as(SetWidgetComparable(7), SWCHash(), eastl::equal_to_2<SetWidget, SetWidgetComparable>());
		VERIFY(itfc->mX == 7);


		// iterator  erase(iterator);
		// iterator  erase(iterator, iterator);
		// size_type erase(const key_type&);

		eastl_size_t n = ihmSW1.erase(SetWidget(99999));
		VERIFY(n == 0);

		n = ihmSW1.erase(SetWidget(17));
		VERIFY(n == 1);

		itf = ihmSW1.find(SetWidget(18));
		VERIFY(itf != ihmSW1.end());
		VERIFY(ihmSW1.validate_iterator(itf) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmSW1.erase(itf);
		VERIFY(itf != ihmSW1.end());
		VERIFY(ihmSW1.validate_iterator(itf) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmSW1.find(SetWidget(18));
		VERIFY(itf == ihmSW1.end());

		itf = ihmSW1.find(SetWidget(19));
		VERIFY(itf != ihmSW1.end());

		IHM_SW::iterator itf2(itf);
		eastl::advance(itf2, 7);
		VERIFY(itf2 != ihmSW1.end());
		VERIFY(ihmSW1.validate_iterator(itf2) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmSW1.erase(itf, itf2);
		VERIFY(itf != ihmSW1.end());
		VERIFY(ihmSW1.validate_iterator(itf) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmSW1.find(SetWidget(19));
		VERIFY(itf == ihmSW1.end());


		// eastl::pair<iterator, iterator>             equal_range(const key_type& k);
		// eastl::pair<const_iterator, const_iterator> equal_range(const key_type& k) const;

		eastl::pair<IHM_SW::iterator, IHM_SW::iterator> p = ihmSW1.equal_range(SetWidget(1));
		VERIFY(p.first != ihmSW1.end());
		VERIFY(p.second != ihmSW1.end());

		eastl::pair<IHM_SW::const_iterator, IHM_SW::const_iterator> pc = ihmSW1Const.equal_range(SetWidget(1));
		VERIFY(pc.first != ihmSW1Const.end());
		VERIFY(pc.second != ihmSW1Const.end());


		// void clear();
		// bool validate() const;
		// int validate_iterator(const_iterator i) const;

		IHM_SW::iterator itTest;
		int iresult = ihmSW1.validate_iterator(itTest);
		VERIFY(iresult == isf_none);

		itTest = ihmSW1.begin();
		iresult = ihmSW1.validate_iterator(itTest);
		VERIFY(iresult == (isf_valid | isf_current | isf_can_dereference));

		itTest = ihmSW1.end();
		iresult = ihmSW1.validate_iterator(itTest);
		VERIFY(iresult == (isf_valid | isf_current));

		ihmSW1.clear();
		ihmSW2.clear();
		VERIFY(ihmSW1.validate());
		VERIFY(ihmSW2.validate());

		itTest = ihmSW1.begin();
		iresult = ihmSW1.validate_iterator(itTest);
		VERIFY(iresult == (isf_valid | isf_current));
	}


	{
		// Test intrusive_hash_map

		const size_t kBucketCount = 37;
		typedef intrusive_hash_map<int, MapWidget, kBucketCount> IHM_MW;

		const size_t kArraySize = 100;
		MapWidget mwArray[kArraySize];

		int nExpectedKeySum = 0; // We use this as a checksum in order to do validity checks below.

		for(size_t i = 0; i < kArraySize; i++)
		{
			mwArray[i].mKey  = (int)i;
			mwArray[i].mX    = (int)i;
			nExpectedKeySum += (int)i;
		}


		// intrusive_hashtable(const Hash&, const Equal&);
		// void swap(this_type& x);
		// size_type size() const;
		// bool empty() const;
		// size_type bucket_count() const;
		// size_type bucket_size(size_type n) const;
		// float load_factor() const;
		// void clear();
		// bool validate() const;

		IHM_MW ihmMW1;
		IHM_MW ihmMW2;

		VERIFY(ihmMW1.size() == 0);
		VERIFY(ihmMW1.empty());
		VERIFY(ihmMW1.validate());
		VERIFY(ihmMW2.validate());

		ihmMW1.swap(ihmMW2);

		VERIFY(ihmMW1.validate());
		VERIFY(ihmMW2.validate());
		VERIFY(ihmMW2.bucket_count() == kBucketCount);
		VERIFY(ihmMW2.bucket_size(0) == 0);
		VERIFY(ihmMW2.bucket_size(kBucketCount - 1) == 0);
		VERIFY(ihmMW1.load_factor() == 0.f);
		VERIFY(ihmMW2.load_factor() == 0.f);

		ihmMW1.clear();
		VERIFY(ihmMW1.validate());
		VERIFY(ihmMW1.begin() == ihmMW1.end());


		// void insert(InputIterator first, InputIterator last);
		// insert_return_type insert(value_type& value);
		// void swap(this_type& x);
		// void clear();

		ihmMW1.clear();
		ihmMW1.insert(mwArray, mwArray + (kArraySize - 10));
		for(int i = 0; i < 10; i++) // insert the remaining elements via the other insert function.
		{
			pair<IHM_MW::iterator, bool> result = ihmMW1.insert(mwArray[(kArraySize - 10) + i]);
			VERIFY(result.second == true);
		}

		VERIFY(ihmMW1.size() == kArraySize);
		VERIFY(ihmMW1.validate());

		for(size_t i = 0; i < kArraySize; i++)
		{
			// Try to re-insert the elements. All insertions should fail.
			pair<IHM_MW::iterator, bool> result = ihmMW1.insert(mwArray[i]);
			VERIFY(result.second == false);
		}

		VERIFY(ihmMW1.size() == kArraySize);
		VERIFY(!ihmMW1.empty());
		VERIFY(ihmMW1.validate());

		ihmMW2.clear();
		ihmMW1.swap(ihmMW2);


		// size_type size() const;
		// bool empty() const;
		// size_type count(const key_type& k) const;
		// size_type bucket_size(size_type n) const;
		// float load_factor() const;
		// size_type bucket(const key_type& k) const

		VERIFY(ihmMW1.validate());
		VERIFY(ihmMW2.validate());
		VERIFY(ihmMW1.size() == 0);
		VERIFY(ihmMW1.empty());
		VERIFY(ihmMW2.size() == kArraySize);
		VERIFY(!ihmMW2.empty());
		VERIFY(ihmMW1.load_factor() == 0.f);
		VERIFY(ihmMW2.load_factor() > 2.f);
		VERIFY(ihmMW1.count(0) == 0);
		VERIFY(ihmMW1.count(999999) == 0);
		VERIFY(ihmMW2.count(0) == 1);
		VERIFY(ihmMW2.count(999999) == 0);
		VERIFY(ihmMW2.bucket_size(0) == 3);     // We just happen to know this should be so based on the distribution.
		VERIFY(ihmMW2.bucket(13)    == (13    % kBucketCount)); // We know this is so because our hash function simply returns n.
		VERIFY(ihmMW2.bucket(10000) == (10000 % kBucketCount)); // We know this is so because our hash function simply returns n.
   

		// iterator begin();
		// const_iterator begin() const;

		ihmMW1.swap(ihmMW2);
		int nSum = 0; 

		for(IHM_MW::iterator it = ihmMW1.begin(); it != ihmMW1.end(); ++it)
		{
			IHM_MW::value_type& v = *it;

			VERIFY(v.mKey == v.mX); // We intentionally made this so above.
			nSum += v.mKey;

			const int iresult = ihmMW1.validate_iterator(it);
			VERIFY(iresult == (isf_valid | isf_current | isf_can_dereference));

			IHM_MW::iterator itf = ihmMW1.find(v.mKey);
			VERIFY(itf == it);
		}

		VERIFY(nSum == nExpectedKeySum);


		// iterator end();
		// const_iterator end() const;

		const IHM_MW& ihmMW1Const = ihmMW1;

		for(IHM_MW::const_iterator itc = ihmMW1Const.begin(); itc != ihmMW1Const.end(); ++itc)
		{
			const IHM_MW::value_type& v = *itc;

			VERIFY(v.mKey == v.mX); // We intentionally made this so above.

			IHM_MW::const_iterator itf = ihmMW1Const.find(v.mKey);
			VERIFY(itf == itc);
		}


		// local_iterator begin(size_type n)
		// local_iterator end(size_type)

		for(IHM_MW::local_iterator itl = ihmMW1.begin(5); itl != ihmMW1.end(5); ++itl)
		{
			IHM_MW::value_type& v = *itl;

			VERIFY(v.mKey == v.mX); // We intentionally made this so above.
		}


		// const_local_iterator begin(size_type n) const
		// const_local_iterator end(size_type) const

		for(IHM_MW::const_local_iterator itlc = ihmMW1Const.begin(5); itlc != ihmMW1Const.end(5); ++itlc)
		{
			const IHM_MW::value_type& v = *itlc;

			VERIFY(v.mKey == v.mX); // We intentionally made this so above.
		}


		// iterator       find(const key_type& k);
		// const_iterator find(const key_type& k) const;

		IHM_MW::iterator itf = ihmMW1.find(99999);
		VERIFY(itf == ihmMW1.end());

		IHM_MW::const_iterator itfc = ihmMW1Const.find(99999);
		VERIFY(itfc == ihmMW1Const.end());


		// iterator       find_as(const U& u);
		// const_iterator find_as(const U& u) const;

		itf = ihmMW1.find_as(7.f);
		VERIFY(itf->mKey == 7);

		itfc = ihmMW1Const.find_as(7.f);
		VERIFY(itfc->mKey == 7);


		// iterator       find_as(const U& u, UHash uhash, BinaryPredicate predicate);
		// const_iterator find_as(const U& u, UHash uhash, BinaryPredicate predicate) const;

		itf = ihmMW1.find_as(7.f, eastl::hash<float>(), eastl::equal_to_2<int, float>());
		VERIFY(itf->mKey == 7);

		itfc = ihmMW1Const.find_as(7.f, eastl::hash<float>(), eastl::equal_to_2<int, float>());
		VERIFY(itfc->mKey == 7);


		// iterator  erase(iterator);
		// iterator  erase(iterator, iterator);
		// size_type erase(const key_type&);

		eastl_size_t n = ihmMW1.erase(99999);
		VERIFY(n == 0);

		n = ihmMW1.erase(17);
		VERIFY(n == 1);

		itf = ihmMW1.find(18);
		VERIFY(itf != ihmMW1.end());
		VERIFY(ihmMW1.validate_iterator(itf) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmMW1.erase(itf);
		VERIFY(itf != ihmMW1.end());
		VERIFY(ihmMW1.validate_iterator(itf) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmMW1.find(18);
		VERIFY(itf == ihmMW1.end());

		itf = ihmMW1.find(19);
		VERIFY(itf != ihmMW1.end());

		IHM_MW::iterator itf2(itf);
		eastl::advance(itf2, 7);
		VERIFY(itf2 != ihmMW1.end());
		VERIFY(ihmMW1.validate_iterator(itf2) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmMW1.erase(itf, itf2);
		VERIFY(itf != ihmMW1.end());
		VERIFY(ihmMW1.validate_iterator(itf) == (isf_valid | isf_current | isf_can_dereference));

		itf = ihmMW1.find(19);
		VERIFY(itf == ihmMW1.end());


		// eastl::pair<iterator, iterator>             equal_range(const key_type& k);
		// eastl::pair<const_iterator, const_iterator> equal_range(const key_type& k) const;

		eastl::pair<IHM_MW::iterator, IHM_MW::iterator> p = ihmMW1.equal_range(1);
		VERIFY(p.first != ihmMW1.end());
		VERIFY(p.second != ihmMW1.end());

		eastl::pair<IHM_MW::const_iterator, IHM_MW::const_iterator> pc = ihmMW1Const.equal_range(1);
		VERIFY(pc.first != ihmMW1Const.end());
		VERIFY(pc.second != ihmMW1Const.end());


		// void clear();
		// bool validate() const;
		// int validate_iterator(const_iterator i) const;

		IHM_MW::iterator itTest;
		int iresult = ihmMW1.validate_iterator(itTest);
		VERIFY(iresult == isf_none);

		itTest = ihmMW1.begin();
		iresult = ihmMW1.validate_iterator(itTest);
		VERIFY(iresult == (isf_valid | isf_current | isf_can_dereference));

		itTest = ihmMW1.end();
		iresult = ihmMW1.validate_iterator(itTest);
		VERIFY(iresult == (isf_valid | isf_current));

		ihmMW1.clear();
		ihmMW2.clear();
		VERIFY(ihmMW1.validate());
		VERIFY(ihmMW2.validate());

		itTest = ihmMW1.begin();
		iresult = ihmMW1.validate_iterator(itTest);
		VERIFY(iresult == (isf_valid | isf_current));
	}


	{
		// Test case of single bucket.
		eastl::intrusive_hash_set<SetWidget, 1, SWHash> hs;
		SetWidget node1, node2, node3;
		 
		node1.mX = 1;
		node2.mX = 2;
		node3.mX = 3;
		 
		hs.insert(node1);
		hs.insert(node2);
		hs.insert(node3);

		const eastl_size_t removeCount = hs.erase(node3);
		VERIFY(removeCount == 1); 
	}


	{
		// Test intrusive_hashtable_iterator(value_type* pNode, value_type** pBucket = NULL)
		eastl::intrusive_hash_set<SetWidget, 37, SWHash> hs;
		SetWidget node1, node2, node3;
		 
		node1.mX = 1;
		node2.mX = 2;
		node3.mX = 3;

		hs.insert(node1);
		hs.insert(node2);
		hs.insert(node3);

		VERIFY(hs.validate());

		hs.remove(node1);
		hs.remove(node2);
		hs.remove(node3);
		
		VERIFY(hs.validate());

		hs.insert(node1);
		hs.insert(node2);
		hs.insert(node3);

		VERIFY(hs.validate());
	}

	return nErrorCount;
}