forked from toptensoftware/simplelib
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap.h
More file actions
863 lines (719 loc) · 24.7 KB
/
map.h
File metadata and controls
863 lines (719 loc) · 24.7 KB
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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
#ifndef __simplelib_map_h__
#define __simplelib_map_h__
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "semantics.h"
#include "plex.h"
/*
Map class implements a map with semantics support. Implemented as a red-black tree
with linked-list between values for fast iteration.
Supports:
* Pseudo random access - operator[](int iIndex)
* Insert/Delete during iteration
* Semanatics
eg:
// map of ints to int
CMap<int, int> mapInts;
// map of ints to object
CMap<int, CMyObject> mapObjects;
// map of ints to object ptrs
CMap<CMyObject*> mapPtrObjects;
// a map of ints to pointers where pointers deleted on removal
CMap<int, CMyObject*, SValue, SOwnedPtr> mapPtrObjects;
// a map of strings to integers, with case insensitivity on the keys
CMap< CString<char>, int, SCaseInsensitive> map;
map.Add("Apples", 10);
map.Add("Pears", 20);
map.Add("Bananas", 30);
// Iterating the above map
for (int i=0; i<map.GetSize(); i++)
{
printf("%s - %i\n", map[i].Key, map[i].Value);
}
*/
namespace SimpleLib
{
template <typename TKey, typename TValue, typename TKeySem=SValue, typename TValueSem=SValue, typename TKeyArg=TKey >
class CMap
{
public:
// Constructor
CMap() :
m_pRoot(&m_Leaf),
m_iSize(0)
{
m_Leaf.m_pParent = nullptr;
m_Leaf.m_pLeft= &m_Leaf;
m_Leaf.m_pRight = &m_Leaf;
m_Leaf.m_bRed = false;
m_iIterPos=-1;
m_pIterNode=nullptr;
}
// Destructor
virtual ~CMap()
{
FreeNode(m_pRoot);
}
// Types
typedef CMap<TKey, TValue, TKeySem, TValueSem, TKeyArg> _CMap;
// Type used as return value from operator[]
class CKeyPair
{
public:
CKeyPair(const TKey& Key, TValue& Value) :
Key(Key),
Value(Value)
{
}
CKeyPair(const CKeyPair& Other) :
Key(Other.Key),
Value(Other.Value)
{
}
const TKey& Key;
TValue& Value;
#ifdef _MSC_VER
private:
// "Occassionally" MSVC compiler gives warning about inability
// to generate assignment operator that it never even uses.
// This seems to fix warning and will give link error if actually needed
CKeyPair& operator=(const CKeyPair& Other);
#endif
};
// Get number of elements in map
int GetCount() const
{
return m_iSize;
}
// Is the map empty?
bool IsEmpty() const
{
return m_iSize==0;
}
// Index based iteration
CKeyPair operator[](int iIndex) const
{
assert(iIndex>=0 && iIndex<m_iSize);
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
if (iIndex==0)
{
m_iIterPos=0;
m_pIterNode=m_pFirst;
return CKeyPair(m_pIterNode->m_KeyPair.m_Key, m_pIterNode->m_KeyPair.m_Value);
}
if (iIndex==m_iSize-1)
{
m_iIterPos=m_iSize-1;
m_pIterNode=m_pLast;
return CKeyPair(m_pIterNode->m_KeyPair.m_Key, m_pIterNode->m_KeyPair.m_Value);
}
if (iIndex==m_iIterPos)
{
return CKeyPair(m_pIterNode->m_KeyPair.m_Key, m_pIterNode->m_KeyPair.m_Value);
}
if (iIndex==m_iIterPos+1)
{
m_iIterPos=iIndex;
m_pIterNode=m_pIterNode->m_pNext;
return CKeyPair(m_pIterNode->m_KeyPair.m_Key, m_pIterNode->m_KeyPair.m_Value);
}
if (iIndex==m_iIterPos-1)
{
m_iIterPos=iIndex;
m_pIterNode=m_pIterNode->m_pPrev;
return CKeyPair(m_pIterNode->m_KeyPair.m_Key, m_pIterNode->m_KeyPair.m_Value);
}
int iDistanceFromIterPos=m_iIterPos-iIndex;
if (iDistanceFromIterPos < 0)
iDistanceFromIterPos = - iDistanceFromIterPos;
int iDistanceFromStart=iIndex;
int iDistanceFromEnd=(m_iSize-1)-iIndex;
if (m_iIterPos>=0 && iDistanceFromIterPos<iDistanceFromEnd && iDistanceFromIterPos<iDistanceFromEnd)
{
while (m_iIterPos<iIndex)
{
m_pIterNode=m_pIterNode->m_pNext;
m_iIterPos++;
}
while (m_iIterPos>iIndex)
{
m_pIterNode=m_pIterNode->m_pPrev;
m_iIterPos--;
}
}
else
{
if (iDistanceFromStart<iDistanceFromEnd)
{
m_pIterNode=m_pFirst;
for (int i=0; i<iIndex; i++)
m_pIterNode=m_pIterNode->m_pNext;
}
else
{
m_pIterNode=m_pLast;
for (int i=0; i<iDistanceFromEnd; i++)
{
m_pIterNode=m_pIterNode->m_pPrev;
}
}
}
m_iIterPos=iIndex;
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
return CKeyPair(m_pIterNode->m_KeyPair.m_Key, m_pIterNode->m_KeyPair.m_Value);
}
// Add an item to the map
void Add(const TKey& Key, const TValue& Value)
{
CNode* pNode = m_pRoot;
CNode* pParent = nullptr;
int iCompare=0;
while (pNode != &m_Leaf)
{
pParent = pNode;
iCompare = TKeySem::Compare(Key, pNode->m_KeyPair.m_Key);
if (iCompare < 0)
pNode = pNode->m_pLeft;
else if (iCompare > 0)
pNode = pNode->m_pRight;
else
{
// Found a duplicate, replace it. We replace the key too, since
// equivalence is not always exact (e.g. case insensitive strings)
TKeySem::OnRemove(pNode->m_KeyPair.m_Key, this);
TValueSem::OnRemove(pNode->m_KeyPair.m_Value, this);
pNode->m_KeyPair.m_Value = TValueSem::OnAdd(Value, this);
pNode->m_KeyPair.m_Key = TKeySem::OnAdd(Key, this);
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
return;
}
}
CNode* pNew = m_NodePlex.Alloc();
pNew->m_pParent = pParent;
pNew->m_pLeft = &m_Leaf;
pNew->m_pRight = &m_Leaf;
pNew->m_bRed = true;
pNew->m_KeyPair.m_Value = TValueSem::OnAdd(Value, this);
pNew->m_KeyPair.m_Key = TKeySem::OnAdd(Key, this);
if (pParent)
{
if (iCompare<0)
{
pParent->m_pLeft = pNew;
pNew->m_pNext=pParent;
pNew->m_pPrev=pParent->m_pPrev;
}
else if (iCompare>0)
{
pParent->m_pRight = pNew;
pNew->m_pPrev=pParent;
pNew->m_pNext=pParent->m_pNext;
}
else
{
assert(false);
}
}
else
{
m_pRoot = pNew;
pNew->m_pPrev=nullptr;
pNew->m_pNext=nullptr;
}
// Fix up traverse links
if (pNew->m_pPrev)
pNew->m_pPrev->m_pNext=pNew;
else
m_pFirst=pNew;
if (pNew->m_pNext)
pNew->m_pNext->m_pPrev=pNew;
else
m_pLast=pNew;
if (m_pIterNode)
{
int iCompare=TKeySem::Compare(Key, m_pIterNode->m_KeyPair.m_Key);
assert(iCompare!=0);
// If the new key is before the current iterate position, update the iterate position
if (iCompare<0)
{
m_pIterNode=m_pIterNode->m_pPrev;
}
}
// Now rebalance the tree.
pNode = pNew;
while (pNode != m_pRoot && pNode->m_pParent->m_bRed)
{
pParent = pNode->m_pParent;
CNode* pGrandParent = pParent->m_pParent;
if (pParent == pGrandParent->m_pLeft)
{
CNode* pUncle = pGrandParent->m_pRight;
if (pUncle->m_bRed)
{
pParent->m_bRed = false;
pUncle->m_bRed = false;
pGrandParent->m_bRed = true;
pNode = pGrandParent;
}
else
{
if (pNode == pParent->m_pRight)
{
pNode = pParent;
RotateLeft(pNode);
}
pNode->m_pParent->m_bRed = false;
pNode->m_pParent->m_pParent->m_bRed = true;
RotateRight(pNode->m_pParent->m_pParent);
}
}
else
{
CNode* pUncle = pGrandParent->m_pLeft;
if (pUncle->m_bRed)
{
pParent->m_bRed = false;
pUncle->m_bRed = false;
pGrandParent->m_bRed = true;
pNode = pGrandParent;
}
else
{
if (pNode == pParent->m_pLeft)
{
pNode = pParent;
RotateRight(pNode);
}
pNode->m_pParent->m_bRed = false;
pNode->m_pParent->m_pParent->m_bRed = true;
RotateLeft(pNode->m_pParent->m_pParent);
}
}
}
m_pRoot->m_bRed = false;
m_iSize++;
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
}
// Remove an item from the map
void Remove(const TKeyArg& Key)
{
RemoveOrDetach(Key, nullptr);
}
// Remove all items from the map
void RemoveAll()
{
FreeNode(m_pRoot);
m_pRoot = &m_Leaf;
m_pFirst = nullptr;
m_pLast = nullptr;
m_iSize = 0;
m_iIterPos = -1;
m_pIterNode = nullptr;
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
}
// Detach an item from the map and return it
TValue Detach(const TKeyArg& Key)
{
TValue val;
RemoveOrDetach(Key, &val);
return val;
}
// Get an item from the map, return default if doesn't exist
const TValue& Get(const TKeyArg& Key, const TValue& Default = TValue()) const
{
CNode* pNode = FindNode(Key);
if (!pNode)
return Default;
return pNode->m_KeyPair.m_Value;
}
// Find an item in the map and return true/false if found or not
bool TryGetValue(const TKeyArg& Key, TValue& Value) const
{
CNode* pNode = FindNode(Key);
if (!pNode)
return false;
Value = pNode->m_KeyPair.m_Value;
return true;
}
// Check if the map contains a key
bool Contains(const TKeyArg& Key) const
{
return FindNode(Key) != nullptr;
}
DEPRECATED("Use GetCount() instead")
int GetSize() const { return GetCount(); }
DEPRECATED("Use TryGetValue() instead")
bool Find(const TKeyArg& Key, TValue& Value) const { return TryGetValue(Key, Value); }
DEPRECATED("Use Contains() instead")
bool HasKey(const TKeyArg& Key) const { return Contains(Key); }
#ifdef _DEBUG
void CheckAll()
{
CheckTree();
CheckChain();
}
#endif
// Implementation
protected:
// CKeyPairInternal
struct CKeyPairInternal
{
TKey m_Key;
TValue m_Value;
};
// CNode
struct CNode
{
CKeyPairInternal m_KeyPair;
CNode* m_pParent;
CNode* m_pLeft;
CNode* m_pRight;
CNode* m_pPrev;
CNode* m_pNext;
bool m_bRed;
};
// Operations
#ifdef _DEBUG
void CheckChain()
{
if (m_pFirst)
{
assert(m_pFirst->m_pPrev == nullptr);
assert(m_pLast != nullptr);
assert(m_pLast->m_pNext == nullptr);
int i = 0;
CNode* pNode = m_pFirst;
while (pNode)
{
if (pNode->m_pPrev)
{
assert(pNode->m_pPrev->m_pNext == pNode);
}
else
{
assert(pNode == m_pFirst);
}
if (pNode->m_pNext)
{
// Check order
int iCompare = TKeySem::Compare(pNode->m_KeyPair.m_Key, pNode->m_pNext->m_KeyPair.m_Key);
assert(iCompare < 0);
assert(pNode->m_pNext->m_pPrev == pNode);
}
else
{
assert(pNode == m_pLast);
}
if (i == m_iIterPos)
{
assert(m_pIterNode == pNode);
}
pNode = pNode->m_pNext;
i++;
}
if (m_iIterPos >= 0)
{
assert(m_pIterNode != nullptr);
}
assert(i == m_iSize);
}
}
bool CheckTree(CNode* pNode = nullptr)
{
int lh = 1, rh = 1;
if (!pNode)
pNode = m_pRoot;
if (pNode->m_pLeft != &m_Leaf)
lh = CheckTree(pNode->m_pLeft);
if (pNode->m_pRight != &m_Leaf)
rh = CheckTree(pNode->m_pRight);
assert(lh == rh);
return !!(lh + !pNode->m_bRed);
}
#endif
// Free a node
void FreeNode(CNode* pNode)
{
if (pNode && pNode != &m_Leaf)
{
FreeNode(pNode->m_pLeft);
FreeNode(pNode->m_pRight);
TKeySem::OnRemove(pNode->m_KeyPair.m_Key, this);
TValueSem::OnRemove(pNode->m_KeyPair.m_Value, this);
m_NodePlex.Free(pNode);
}
}
// Find the next node
CNode* nextNode(CNode* pNode)
{
if (pNode->m_pRight != &m_Leaf)
{
pNode = pNode->m_pRight;
while (pNode->m_pLeft != &m_Leaf)
pNode = pNode->m_pLeft;
return pNode;
}
CNode* pParent = pNode->m_pParent;
while (pParent != &m_Leaf && pNode == &m_Leaf)
{
pNode = pParent;
pParent = pParent->m_pParent;
}
return pParent;
}
// Rotate tree left
void RotateLeft(CNode* x)
{
CNode* parent = m_Leaf.m_pParent;
CNode* y = x->m_pRight;
// Turn y's left subtree into x's right subtree
x->m_pRight = y->m_pLeft;
x->m_pRight->m_pParent = x;
// Link x's parent to y
y->m_pParent = x->m_pParent;
if (x != m_pRoot)
{
if (x->m_pParent->m_pLeft == x)
x->m_pParent->m_pLeft = y;
else
x->m_pParent->m_pRight = y;
}
else
m_pRoot = y;
// Put x on y's left
y->m_pLeft = x;
x->m_pParent = y;
m_Leaf.m_pParent = parent;
}
// Rotate tree right
void RotateRight(CNode* y)
{
CNode* parent = m_Leaf.m_pParent;
CNode* x = y->m_pLeft;
// Turn x's right subtree into y's left subtree
y->m_pLeft = x->m_pRight;
y->m_pLeft->m_pParent = y;
// Link y's parent to x
x->m_pParent = y->m_pParent;
if (y != m_pRoot)
{
if (y->m_pParent->m_pLeft == y)
y->m_pParent->m_pLeft = x;
else
y->m_pParent->m_pRight = x;
}
else
m_pRoot = x;
// Put y on x's right
x->m_pRight = y;
y->m_pParent = x;
m_Leaf.m_pParent = parent;
}
// Helper for Remove() and Detach()
void RemoveOrDetach(const TKeyArg& Key, TValue* pvalDetached)
{
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
CNode* z = m_pRoot;
while (z != &m_Leaf)
{
int iCompare = TKeySem::Compare(Key, z->m_KeyPair.m_Key);
if (iCompare < 0)
z = z->m_pLeft;
else if (iCompare > 0)
z = z->m_pRight;
else
break;
}
if (z == &m_Leaf)
return;
CNode* y = (z->m_pLeft == &m_Leaf || z->m_pRight == &m_Leaf) ? z : nextNode(z);
CNode* x = (y->m_pLeft != &m_Leaf) ? y->m_pLeft : y->m_pRight;
// Ensure that x->m_pParent is correct.
// This is needed in case x == &m_Leaf
x->m_pParent = y->m_pParent;
if (y != m_pRoot)
{
if (y->m_pParent->m_pLeft == y)
y->m_pParent->m_pLeft = x;
else
y->m_pParent->m_pRight = x;
}
else
m_pRoot = x;
if (m_pIterNode)
{
int iCompare = TKeySem::Compare(Key, m_pIterNode->m_KeyPair.m_Key);
if (iCompare <= 0)
{
m_pIterNode = m_pIterNode->m_pNext;
}
}
TKeySem::OnRemove(z->m_KeyPair.m_Key, this);
if (!pvalDetached)
{
TValueSem::OnRemove(z->m_KeyPair.m_Value, this);
}
else
{
TValueSem::OnDetach(z->m_KeyPair.m_Value, this);
*pvalDetached = z->m_KeyPair.m_Value;
}
if (y != z)
{
// deleting value in z, but keeping z node and moving value from y node
z->m_KeyPair.m_Key = y->m_KeyPair.m_Key;
z->m_KeyPair.m_Value = y->m_KeyPair.m_Value;
z->m_pNext = y->m_pNext;
if (z->m_pNext)
z->m_pNext->m_pPrev = z;
else
m_pLast = z;
if (m_pIterNode == y)
m_pIterNode = z;
}
else
{
// Update linked list
if (z->m_pPrev)
z->m_pPrev->m_pNext = z->m_pNext;
else
m_pFirst = z->m_pNext;
if (z->m_pNext)
z->m_pNext->m_pPrev = z->m_pPrev;
else
m_pLast = z->m_pPrev;
if (m_pIterNode == z)
{
m_pIterNode = m_pIterNode->m_pNext;
if (!m_pIterNode)
{
m_iIterPos = -1;
}
}
}
// Rebalance the tree (see page 274 of Introduction to Algorithms)
if (!y->m_bRed)
{
CNode* pNode = x;
while (pNode != m_pRoot && !pNode->m_bRed)
{
if (pNode == pNode->m_pParent->m_pLeft)
{
CNode* pSibling = pNode->m_pParent->m_pRight;
if (pSibling->m_bRed)
{
// Case 1: Sibling is m_bRed
pSibling->m_bRed = false;
pNode->m_pParent->m_bRed = true;
RotateLeft(pNode->m_pParent);
pSibling = pNode->m_pParent->m_pRight;
}
if (!pSibling->m_pLeft->m_bRed && !pSibling->m_pRight->m_bRed)
{
// Case 2: Sibling and its children are all black
pSibling->m_bRed = true;
pNode = pNode->m_pParent;
continue;
}
else if (!pSibling->m_pRight->m_bRed)
{
// Case 3: Sibling and its right child are both black
pSibling->m_pLeft->m_bRed = false;
pSibling->m_bRed = true;
RotateRight(pSibling);
pSibling = pNode->m_pParent->m_pRight;
}
// Case 4: Sibling and its left child are both black
pSibling->m_bRed = pNode->m_pParent->m_bRed;
pNode->m_pParent->m_bRed = false;
pSibling->m_pRight->m_bRed = false;
RotateLeft(pNode->m_pParent);
pNode = m_pRoot;
}
else
{
CNode* pSibling = pNode->m_pParent->m_pLeft;
if (pSibling->m_bRed)
{
// Case 5: Sibling is m_bRed
pSibling->m_bRed = false;
pNode->m_pParent->m_bRed = true;
RotateRight(pNode->m_pParent);
pSibling = pNode->m_pParent->m_pLeft;
}
if (!pSibling->m_pLeft->m_bRed && !pSibling->m_pRight->m_bRed)
{
// Case 6: Sibling and its children are all black
pSibling->m_bRed = true;
pNode = pNode->m_pParent;
continue;
}
else if (!pSibling->m_pLeft->m_bRed)
{
// Case 7: Sibling and its left child are both black
pSibling->m_pRight->m_bRed = false;
pSibling->m_bRed = true;
RotateLeft(pSibling);
pSibling = pNode->m_pParent->m_pLeft;
}
// Case 8: Sibling and its right child are both black
pSibling->m_bRed = pNode->m_pParent->m_bRed;
pNode->m_pParent->m_bRed = false;
pSibling->m_pLeft->m_bRed = false;
RotateRight(pNode->m_pParent);
pNode = m_pRoot;
}
}
pNode->m_bRed = false;
}
m_NodePlex.Free(y);
m_iSize--;
#ifdef _DEBUG_CHECKS
CheckAll();
#endif
}
// Find a node with specified key
CNode* FindNode(const TKeyArg& Key) const
{
CNode* pNode = m_pRoot;
while (pNode != &m_Leaf)
{
int iCompare = TKeySem::Compare(Key, pNode->m_KeyPair.m_Key);
if (iCompare < 0)
pNode = pNode->m_pLeft;
else if (iCompare > 0)
pNode = pNode->m_pRight;
else
return pNode;
}
return nullptr;
}
// Attributes
CPlex<CNode> m_NodePlex;
CNode* m_pRoot;
CNode* m_pFirst;
CNode* m_pLast;
CNode m_Leaf;
mutable int m_iIterPos;
mutable CNode* m_pIterNode;
int m_iSize;
private:
// Unsupported
CMap(const CMap& Other);
CMap& operator=(const CMap& Other);
};
} // namespace
#endif // __simplelib_map_h__