-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFastCollection.cls
More file actions
1929 lines (1788 loc) · 49.2 KB
/
FastCollection.cls
File metadata and controls
1929 lines (1788 loc) · 49.2 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
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "FastCollection"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
' George's FastCollection
' Only Add, and Find.
' Key as string may be a hex number (used for enumerates)
' zero$ has chr$(1)
Const Zero$ = ""
Private Declare Function CompareString Lib "kernel32" Alias "CompareStringW" (ByVal Locale As Long, ByVal dwCmpFlags As Long, ByVal lpString1 As Long, ByVal cchCount1 As Long, ByVal lpString2 As Long, ByVal cchCount2 As Long) As Long
Const NowDec$ = ","
' No same key. --- this is changed
Private AllowSameKey As Boolean
' We can remove a key - if AllowSameKey=false
' We can add key (only unique keys)
' return variant (can be anything)
'**************
'* Propertiea:
'* Count
'*'* from 1 to Count we can access all the members of FastCollection
'* .Index=1 used for input/output
'* We can get Key or Value
'* .KeyToString
'* .Value
'* We can change Valus
'* set .ValueObj = objectX
'* .ValueVar
'**************************
'* Methods
'* AddKey "10" [, variant]
'* ToKey "10"
'* SwapValues "10", "30"
'*
'* .Done ..operation is ok
'* .Remove 10
'* .AddKey without parameter add 1 to lastkey
'* .LastKey
'* .LastIndex
'* .Frwd (for index, exit if not .done)
'* .Back (for index, exit if not .done)
Private mSortstyle As VbCompareMethod
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Public Type Container
struct As Object
offset As Long ' old ivalue
items As Long
End Type
Private Type item ' if you add change swapb (check with lenb() function)
Key As String
KeyType As Integer
iValue As Variant
sValue As Long
firsthash As Long
lastpos As Long
Pleft As Long ' a list
End Type
Private PriveSpace() As item
Dim MaxSpace As Long
Dim hashlen As Long
Dim toplim As Long
Public Stable As Long
Private Declare Sub GetMem1 Lib "msvbvm60" (ByVal addr As Long, retval As Byte)
Private Declare Sub GetMem2 Lib "msvbvm60" (ByVal addr As Long, retval As Integer)
Private lastfind As String
Private lasttype As Integer
Private lastkey As String
Private Hash() As Long
Public Done As Boolean
Public Index As Long
Public structLen As Long
Private ParentIndex As Long
Public NumericSort As Boolean
Public IamBusy As Boolean
Public useclid As Long
Private UseUcaseKeys As Boolean, Sorted As Boolean
Private uScol() As Byte, useSCol As Boolean
Private entrance As Long
Public Tag As String
Dim zeroitem As item, Piv As item, swapb(40) As Byte
Private Sub Class_Initialize()
MaxSpace = 5
ReDim PriveSpace(MaxSpace) As item, Hash(MaxSpace * 2 + 3)
hashlen = MaxSpace * 2 + 3
toplim = -1
mSortstyle = vbTextCompare
End Sub
Public Sub ResetGui()
MaxSpace = 50
ReDim PriveSpace(MaxSpace) As item, Hash(MaxSpace * 2 + 3)
hashlen = MaxSpace * 2 + 3
toplim = -1
mSortstyle = vbTextCompare
End Sub
Friend Sub MakeSpace(ThatSpace As Long, thatStyle As VbCompareMethod)
MaxSpace = ThatSpace
ReDim PriveSpace(MaxSpace) As item
toplim = -1
mSortstyle = thatStyle
End Sub
Friend Sub AddMoreSpace(ThatSpace As Long, thatStyle As VbCompareMethod)
MaxSpace = MaxSpace + ThatSpace
ReDim Preserve PriveSpace(MaxSpace) As item
mSortstyle = thatStyle
End Sub
Public Sub SetBinaryCompare()
mSortstyle = vbBinaryCompare
End Sub
Public Sub SetTextCompare()
mSortstyle = vbTextCompare
End Sub
Public Sub SetDataBaseCompare()
mSortstyle = vbDatabaseCompare
End Sub
Public Sub AddKey2(RHS, Optional aValue As Variant)
IamBusy = True
Index = -1
lastkey = Normalize(RHS)
If Len(lastkey) = 0 Then RHS = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0): lastkey = RHS
Done = False
lasttype = VarType(RHS)
If Not IsMissing(aValue) Then
If IsObject(aValue) Then
Value = -1
Set ValueObj = aValue
Else
Value = aValue
End If
Else
Value = aValue
End If
IamBusy = False
End Sub
Public Sub AddKey(RHS, Optional aValue As Variant)
Index = -1
lastkey = Normalize(RHS)
If Len(lastkey) = 0 Then RHS = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0): lastkey = RHS
Done = False
lasttype = VarType(RHS)
If Not IsMissing(aValue) Then
If IsObject(aValue) Then
Value = -1
Set ValueObj = aValue
Else
Value = aValue
End If
Else
Value = aValue
End If
If Index >= 0 Then
PriveSpace(Index).KeyType = lasttype
Else
' PriveSpace(Index).KeyType = 0 ' invalid
End If
End Sub
Public Property Get StructOffset() As Long
Dim zz
'If structLen = 0 Then Stop
If Index > -1 Then
zz = PriveSpace(Index).iValue
If VarType(zz) = vbUserDefinedType Then
StructOffset = zz.offset
End If
End If
End Property
Public Property Get StructMany() As Long
Dim zz
If Index > -1 Then
zz = PriveSpace(Index).iValue
If VarType(zz) = vbUserDefinedType Then
StructMany = zz.items
End If
End If
End Property
Public Property Get StructObj() As Object
Dim zz
If Index > -1 Then
zz = PriveSpace(Index).iValue
If VarType(zz) = vbUserDefinedType Then
Set StructObj = zz.struct
End If
End If
End Property
Friend Sub AddKeyStruct(RHS, offset As Long, manyitems As Long, obj As Object)
Dim mycon As Container, aValue
mycon.offset = offset
mycon.items = manyitems
Set mycon.struct = obj
Index = -1
aValue = CVar(mycon)
lastkey = Normalize(RHS)
If Len(lastkey) = 0 Then RHS = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0): lastkey = RHS
Done = False
lasttype = VarType(RHS)
If Not IsMissing(aValue) Then
If IsObject(aValue) Then
Value = -1
Set ValueObj = aValue
Else
Value = aValue
End If
Else
Value = aValue
If Index >= 0 Then
PriveSpace(Index).KeyType = lasttype
Else
' PriveSpace(Index).KeyType = 0 ' invalid
End If
End If
End Sub
Public Sub Sort()
If toplim = -1 Then Exit Sub
IamBusy = True
If AllowSameKey Then
If Stable Then
InsertionSort PriveSpace(), LBound(PriveSpace()), toplim
Else
If NumericSort Then
QuickSortItemsNumbers PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItemsWithSameKey PriveSpace(), LBound(PriveSpace()), toplim
End If
End If
Else
If NumericSort Then
QuickSortItemsNumbers PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItems PriveSpace(), LBound(PriveSpace()), toplim
End If
End If
Rehash
Sorted = True
IamBusy = False
End Sub
Public Sub SortDes()
If toplim = -1 Then Exit Sub
IamBusy = True
If AllowSameKey Then
If Stable Then
InsertionSort PriveSpace(), LBound(PriveSpace()), toplim, 1
Else
If NumericSort Then
QuickSortItemsRevNumbers PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItemsRevWithSameKey PriveSpace(), LBound(PriveSpace()), toplim
End If
End If
Else
If NumericSort Then
QuickSortItemsRevNumbers PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItemsRev PriveSpace(), LBound(PriveSpace()), toplim
End If
End If
Rehash
Sorted = True
IamBusy = False
End Sub
Public Sub ToKey(RHS)
Done = Find(RHS)
If Done Then lastkey = Normalize(RHS)
End Sub
Public Sub RemoveWithNoFind()
'If AllowSameKey Then Exit Sub
Dim new_item As item
Dim k As Long, k1 As Long, vvv As Variant, top1 As Long
If toplim < 0 Then Exit Sub
top1 = toplim
If Done Then
Sorted = False
If ParentIndex > -1 Then
PriveSpace(ParentIndex).Pleft = PriveSpace(Index).Pleft
Else
Hash(PriveSpace(Index).lastpos) = PriveSpace(Index).Pleft
End If
If top1 = Index Then
PriveSpace(top1) = new_item
Else
SwapVariant vvv, PriveSpace(top1).iValue
PriveSpace(Index).iValue = -1
PriveSpace(Index) = PriveSpace(top1)
PriveSpace(top1) = new_item
SwapVariant vvv, PriveSpace(Index).iValue
End If
k = Hash(PriveSpace(Index).lastpos) - 1
If k = top1 Then
' we have to give the new position to Hash()
Hash(PriveSpace(Index).lastpos) = Index + 1
Else
Do While k >= 0 And k <> top1 And k <> k1
k1 = k
k = PriveSpace(k).Pleft - 1
Loop
If k = k1 Then
Rehash
ElseIf k = top1 Then
PriveSpace(k1).Pleft = Index + 1
End If
End If
here:
toplim = toplim - 1
ReduceHash toplim
End If
End Sub
Public Sub drop(RHS)
'If Not AllowSameKey Then Exit Sub
RHS = RHS - 1
If (toplim - RHS) >= 0 And (RHS >= 0) Then
Dim i As Long
For i = toplim To RHS Step -1
With PriveSpace(i)
If .Pleft > 0 Then
Hash(.lastpos) = .Pleft
.Pleft = 0
Else
Hash(.lastpos) = 0
End If
.Key = vbNullString
.iValue = CDbl(0)
End With
toplim = RHS - 1
ReduceHash toplim
Next i
Else
MaxSpace = 5
ReDim PriveSpace(MaxSpace) As item, Hash(MaxSpace * 2 + 3)
hashlen = MaxSpace * 2 + 3
toplim = -1
mSortstyle = vbTextCompare
End If
End Sub
Public Sub Remove(RHS)
If AllowSameKey Then Exit Sub
Dim k As Long, k1 As Long, vvv As Variant, top1 As Long, nDx As Long, Parndx As Long
If toplim < 0 Then Exit Sub
top1 = toplim
If Find2(RHS, Parndx, nDx) Then
Sorted = False
Done = True
Index = nDx
' here we make a clean to pointers to PriveSpace, so we exclude the removing item
If Parndx > -1 Then
' if we have a parent then just push to parent the Pleft pointer
' Pleft is always +1 (so Pleft 0 give -1 null for this context)
PriveSpace(Parndx).Pleft = PriveSpace(nDx).Pleft
Else
' so we have no parent, just out Pleft to Hash
Hash(PriveSpace(nDx).lastpos) = PriveSpace(nDx).Pleft
End If
' we don't have to see Hash() any more for RHS
' but we have to see Hash() for top1
Dim new_item As item
' We have to get change top1 to ndx, maybe we remove top1
' we can check this but it is faster to not check this (more often top1 isn't ndx)
' Using SwapVariant we can swap any kind of Variant, including objects (swaping pointers only)
If top1 = nDx Then
PriveSpace(top1) = new_item
Else
SwapVariant vvv, PriveSpace(top1).iValue
PriveSpace(nDx).iValue = -1 ' is good to pass a number - so we break any pointer to object
PriveSpace(nDx) = PriveSpace(top1) ' now we perform a copy (no objects included)
PriveSpace(top1) = new_item
' so now we put back iValue (maybe is an object)
SwapVariant vvv, PriveSpace(nDx).iValue
End If
' here Lastpos is from previous PriveSpace(top1) which is PriveSpace(ndx)
k = Hash(PriveSpace(nDx).lastpos) - 1
If k = top1 Then
' we have to give the new position to Hash()
Hash(PriveSpace(nDx).lastpos) = nDx + 1
Else
Do While k >= 0 And k <> top1 And k <> k1
k1 = k
k = PriveSpace(k).Pleft - 1
Loop
If k = k1 Then
Rehash
ElseIf k = top1 Then
PriveSpace(k1).Pleft = nDx + 1
End If
End If
here:
toplim = toplim - 1
ReduceHash toplim
Else
Done = False
End If
End Sub
Property Let Value(RHS As Variant)
Done = False
If Index = -1 Then
ItemCreator lastkey, RHS
Else
SwapVariant PriveSpace(Index).iValue, RHS
End If
Done = True
End Property
Property Set ValueObj(RHS As Variant)
Done = False
If Index = -1 Then
ItemCreator lastkey, RHS
Else
Set PriveSpace(Index).iValue = RHS
End If
Done = True
End Property
Property Get sValue() As Long
Done = False
If Index = -1 Then
Else
Done = True
sValue = PriveSpace(Index).sValue
End If
End Property
Property Let sValue(RHS As Long)
If Index = -1 Then
Else
Done = True
PriveSpace(Index).sValue = RHS
End If
End Property
Property Get KeyTypeValue() As Integer
Done = False
If Index = -1 Then
Else
Done = True
KeyTypeValue = PriveSpace(Index).KeyType
End If
End Property
Property Let KeyTypeValue(RHS As Integer)
If Index = -1 Then
Else
Done = True
PriveSpace(Index).KeyType = RHS
End If
End Property
Property Get Value() As Variant
Done = False
If Index = -1 Then
ElseIf Not IsObject(PriveSpace(Index).iValue) Then
Done = True
Value = PriveSpace(Index).iValue
If structLen > 0 Then
Value = Value.offset
End If
If VarTypeName(Value) = "Error" Then
Value = MyVal()
If VarType(Value) = vbString Then Value = PriveSpace(Index).Key
End If
End If
If VarType(Value) = vbUserDefinedType Then
'Stop
End If
End Property
Public Function IsString() As Boolean
Dim n As Byte
Done = False
If Index = -1 Then
Else
Done = True
GetMem1 VarPtr(PriveSpace(Index).iValue), n
If n = 10 Then n = PriveSpace(Index).KeyType
End If
IsString = n = 8
End Function
Private Function MyVal() As Variant
On Error Resume Next
MyVal = PriveSpace(Index).Key
Select Case PriveSpace(Index).KeyType
Case vbString
If MyVal Like "[-0-9.]*" Then
MyVal = CDbl(Replace$(MyVal, ".", NowDec$))
Else
MyVal = vbNullString
End If
Case vbDouble
MyVal = CDbl(Replace$(MyVal, ".", NowDec$))
Case vbCurrency
MyVal = CCur(Replace$(MyVal, ".", NowDec$))
Case vbDecimal
MyVal = CDec(Replace$(MyVal, ".", NowDec$))
Case 20
MyVal = cInt64(MyVal)
Case 5
Case Else
MyVal = CDbl(Replace$(MyVal, ".", NowDec$))
End Select
End Function
Function ValueType(ch As Long, p As Variant, s As String) As Boolean
Done = False
Dim val1 As Variant
If Index = -1 Then
ValueType = False
ElseIf Not IsObject(PriveSpace(Index).iValue) Then
ValueType = True
Done = True
val1 = PriveSpace(Index).iValue
If structLen > 0 Then
val1 = val1.offset
End If
If CheckInt64(val1) Then
If ch = 2 Then
s = val1
Else
p = 0
On Error Resume Next
p = val1
End If
ElseIf Typename(val1) = "Error" Then
If ch = 2 Then
s = KeyToString
Else
p = 0
On Error Resume Next
p = KeyToNumber
End If
Else
If ch = 2 Then
s = val1
Else
p = 0
On Error Resume Next
p = val1
End If
End If
End If
End Function
Property Get ValueObj() As Variant
Done = False
If Index = -1 Then
ElseIf IsObject(PriveSpace(Index).iValue) Then
Set ValueObj = PriveSpace(Index).iValue
Done = True
End If
End Property
Friend Sub ExpandHash()
hashlen = MaxSpace * 2 + 3
Rehash
End Sub
Private Sub Rehash()
Dim i As Long
ReDim Hash(hashlen) As Long
For i = 0 To toplim
place HashFunc2(i), i
Next i
End Sub
Private Function CheckHash() As Boolean
Dim i As Long
For i = 0 To toplim
If PriveSpace(i).Pleft > 0 Then
If PriveSpace(PriveSpace(i).Pleft - 1).Key = vbNullString Then Exit Function
If i = (PriveSpace(i).Pleft - 1) Then Exit Function
End If
Next i
CheckHash = True
End Function
Private Sub ReduceHash(newTop As Long)
entrance = entrance + 1
If entrance > 0 Then Exit Sub
If newTop <= 5 Then
If newTop < 0 Then
newTop = -1
toplim = -1
MaxSpace = 5
ReDim PriveSpace(MaxSpace) As item
hashlen = MaxSpace * 2 + 3
ReDim Hash(hashlen)
ElseIf MaxSpace > 40 Then
MaxSpace = 5
ReDim Preserve PriveSpace(MaxSpace) As item
hashlen = MaxSpace * 2 + 3
Rehash
End If
Else
If MaxSpace - newTop + 1 > 2 * newTop + 2 Then
MaxSpace = 2 * (newTop + 1) + 1
hashlen = MaxSpace * 2 + 3
ReDim Preserve PriveSpace(MaxSpace) As item
Rehash
End If
End If
entrance = entrance - 1
End Sub
Public Function Normalize(Key) As String
If VarType(Key) = vbString Then
If UseUcaseKeys Then
Normalize = myUcase(Key)
Else
Normalize = Key
End If
ElseIf VarType(Key) = vbBoolean Then
Normalize = str(CLng(Key))
Else
Normalize = LTrim$(str$(Key))
End If
End Function
Function ChangeKey(key1, Key2)
If AllowSameKey Then Exit Function
Dim Key As String, NewKey As String
Dim k As Long
If key1 = Key2 Then ChangeKey = True
Key = Normalize(key1)
If Len(Key) = 0 Then Exit Function
If ExistKey(Key2) Then Exit Function
NewKey = Normalize(Key2)
If Len(NewKey) = 0 Then Exit Function
k = Hash(HashFunc(Key)) - 1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then
PriveSpace(k).Key = NewKey
PriveSpace(k).firsthash = HD(NewKey)
ReDim Hash(MaxSpace * 2 + 3)
hashlen = MaxSpace * 2 + 3
Rehash
ChangeKey = True
Sorted = False
Exit Function
End If
k = PriveSpace(k).Pleft - 1
Loop Until k < 0
End If
End Function
Sub swap(key1, Key2)
Dim k As Long, c As item
If Find(key1) Then
k = Index
If Find(Key2) Then
c = PriveSpace(k): PriveSpace(k) = PriveSpace(Index): PriveSpace(Index) = c
Index = k
Rehash
Sorted = False
End If
End If
End Sub
Sub SwapValues(key1, Key2)
Dim k As Long
If Find(key1) Then
k = Index
If Find(Key2) Then
SwapVariant PriveSpace(k).iValue, PriveSpace(Index).iValue
End If
End If
End Sub
Sub SwapNext(key1)
Dim k As Long
On Error Resume Next
If Done Then
k = Index
If Find(key1) Then
SwapVariant PriveSpace(k).iValue, PriveSpace(Index).iValue
End If
End If
End Sub
Sub SwapByIndex(RHS As Long)
On Error Resume Next
If Done Then
SwapVariant PriveSpace(RHS).iValue, PriveSpace(Index).iValue
Index = RHS
End If
End Sub
Private Function Malloc() As Long
If toplim + 1 >= MaxSpace Then
MaxSpace = MaxSpace * 2
ReDim Preserve PriveSpace(MaxSpace) As item
If MaxSpace > hashlen * 3 / 4 Then ExpandHash
End If
toplim = toplim + 1
Malloc = toplim
End Function
Property Get Count()
Count = toplim + 1
End Property
Public Property Let UcaseKeys(RHS)
If toplim = -1 Then
UseUcaseKeys = CBool(RHS)
End If
End Property
Property Get IsEmpty()
IsEmpty = toplim = -1
End Property
Property Get LastKnown() As String
LastKnown = lastfind
End Property
Function IsObj() As Boolean
If Index = -1 Then
Else
IsObj = IsObject(PriveSpace(Index).iValue)
End If
End Function
Function IsObjAt(curitem As Long, peekvalue) As Boolean
If Index = -1 Then
Else
If IsObject(PriveSpace(Index).iValue) Then
Set peekvalue = PriveSpace(Index).iValue
IsObjAt = True
End If
End If
End Function
Function IsEnum(p As Variant) As Boolean
Dim useHandler As mHandler
If Index = -1 Then
ElseIf IsObject(PriveSpace(Index).iValue) Then
If VarTypeName(PriveSpace(Index).iValue) = "mHandler" Then
Set useHandler = PriveSpace(Index).iValue
IsEnum = useHandler.t1 = 4
If IsEnum Then
If myVarType(useHandler.index_cursor, vbString) Then
p = useHandler.index_cursor
Else
p = useHandler.index_cursor * useHandler.sign
End If
End If
End If
End If
End Function
Function Find(RHS) As Boolean
Dim k As Long, Key As String, k1 As Long
Key = Normalize(RHS)
If Len(Key) = 0 Then Key = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
ParentIndex = -1
Done = False
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then Find = True: lastfind = Key: Index = k: Done = True: Exit Function
ParentIndex = k
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k1 = k
If k1 = k Then
Rehash
k = Hash(HashFunc(Key)) - 1
k1 = -2
ParentIndex = -1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then Find = True: lastfind = Key: Index = k: Done = True: Exit Function
ParentIndex = k
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
End If
End If
End If
End Function
Function FindOne(RHS, num) As Boolean
Dim k As Long, Key As String, k1 As Long
Key = Normalize(RHS)
If Len(Key) = 0 Then Key = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
ParentIndex = -1
Done = False
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then
num = num + 1
If num = 0 Then FindOne = True: lastfind = Key: Index = k: Done = True: Exit Function
End If
ParentIndex = k
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k1 = k
If k1 = k Then
Rehash
k = Hash(HashFunc(Key)) - 1
k1 = -2
ParentIndex = -1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then
num = num + 1
If num = 0 Then FindOne = True: lastfind = Key: Index = k: Done = True: Exit Function
End If
ParentIndex = k
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
End If
End If
End If
End Function
Private Function Find2(RHS, Parndx As Long, nDx As Long) As Boolean
Dim k As Long, Key As String, k1 As Long
Key = Normalize(RHS)
If Len(Key) = 0 Then Key = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
Parndx = -1
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then Find2 = True: nDx = k: Exit Function
Parndx = k
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k1 = k
If k1 = k Then
Parndx = -1
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then Find2 = True: nDx = k: Exit Function
Parndx = k
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k1 = k
End If
End If
End If
End Function
Function ExistKey0(RHS) As Boolean
If AllowSameKey Then Exit Function
Dim k As Long, Key As String, k1 As Long
Key = Normalize(RHS)
If Len(Key) = 0 Then Key = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey0 = True: Index = k: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k1 = k
If k = k1 Then
Rehash
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey0 = True: Index = k: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k1 = k
End If
End If
End If
End Function
Function ExistKey(RHS) As Boolean
Dim k As Long, k1 As Long, Key As String
Key = Normalize(RHS)
If Len(Key) = 0 Then Key = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
k = Hash(HashFunc(Key)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey = True: Index = k: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
If k = k1 Then
Rehash
k = Hash(HashFunc(Key)) - 1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey = True: Index = k: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
End If
End If
End If
End Function
Function ExistKey3(RHS) As Boolean
Dim k As Long, k1 As Long, Key As String
Key = Normalize(RHS)
If Len(Key) = 0 Then Key = Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
k1 = -2
k = Hash(HashFunc(Key)) - 1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey3 = True: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
If k = k1 Then
Rehash
k = Hash(HashFunc(Key)) - 1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey3 = True: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
End If
End If
End If
End Function
Private Function ExistKey2(Key As String, nkey As Long) As Boolean
Dim k As Long, k1 As Long
If Len(Key) = 0 Then ExistKey2 = True: Exit Function
k = Hash(HashFunc1(nkey)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey2 = True: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
If k = k1 Then
Rehash
k = Hash(HashFunc(Key)) - 1
If k >= 0 Then
Do
If PriveSpace(k).Key = Key Then ExistKey2 = True: Exit Function
k1 = k
k = PriveSpace(k).Pleft - 1
Loop Until k < 0 Or k = k1
End If
End If
End If
End Function
Private Sub ItemCreator(Key As String, nValue As Variant)
Dim a As Long, kk As Long
Done = False
Sorted = False
kk = HD(Key)
If Not AllowSameKey Then If ExistKey2(Key, kk) Then Exit Sub ' done is false