-
Notifications
You must be signed in to change notification settings - Fork 3
/
BaseCollection.cls
1666 lines (1540 loc) · 42.2 KB
/
BaseCollection.cls
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 = "BaseCollection"
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 enumarates)
' 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
Public NowDec$
' No same key. --- this is changed
Private AllowSameKey As Boolean
Private mSortstyle As VbCompareMethod
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" ( _
lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Type item
Key As String
KeyType As Integer
iValue As Variant
sValue As Long
sValue2 As Currency
firsthash As Long
lastpos As Long
Pleft As Long ' a list
KeyC As Currency
firsthash1 As Long
lastpos1 As Long
Pleft1 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 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
Private Hash1() 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
Private uScol() As Byte, useSCol As Boolean
Private Sub Class_Initialize()
MaxSpace = 500
ReDim PriveSpace(MaxSpace) As item, Hash(MaxSpace * 2 + 3), Hash1(MaxSpace * 2 + 3)
hashlen = MaxSpace * 2 + 3
toplim = -1
mSortstyle = vbTextCompare
NowDec$ = DefaultDec$
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, KeyC As Currency, 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(KeyC) = -1
Set ValueObj(KeyC) = aValue
Else
Value(KeyC) = aValue
End If
Else
Value(KeyC) = aValue
End If
IamBusy = False
End Sub
Public Sub AddKey(RHS, KeyC As Currency, 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(KeyC) = -1
Set ValueObj(KeyC) = aValue
Else
Value(KeyC) = aValue
End If
Else
Value(KeyC) = aValue
If index >= 0 Then
PriveSpace(index).KeyType = lasttype
Else
PriveSpace(index).KeyType = 0 ' invalid
End If
End If
End Sub
Public Sub AddSecondKey(Optional aValue As Variant)
If index <> -1 Then
PriveSpace(index).KeyC = CCur(aValue)
End If
End Sub
Public Sub Sort()
If toplim = -1 Then Exit Sub
If AllowSameKey Then
If Stable Then
InsertionSort PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItemsNumbers PriveSpace(), LBound(PriveSpace()), toplim
End If
Else
If NumericSort Then
QuickSortItemsNumbers PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItems PriveSpace(), LBound(PriveSpace()), toplim
End If
End If
ReHashAll
End Sub
Public Sub SortDes()
If toplim = -1 Then Exit Sub
If AllowSameKey Then
If Stable Then
InsertionSort PriveSpace(), LBound(PriveSpace()), toplim, 1
Else
QuickSortItemsRevNumbers PriveSpace(), LBound(PriveSpace()), toplim
End If
Else
If NumericSort Then
QuickSortItemsRevNumbers PriveSpace(), LBound(PriveSpace()), toplim
Else
QuickSortItemsRev PriveSpace(), LBound(PriveSpace()), toplim
End If
End If
ReHashAll
End Sub
Public Sub ToKey(RHS)
Done = Find(RHS)
If Done Then lastkey = Normalize(RHS)
End Sub
Public Sub ToKey2(RHS As Currency)
Dim dummy As Long, dummy1 As Long
Done = Find22(RHS, dummy, dummy1)
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
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 = Hash1(PriveSpace(index).lastpos1) - 1
If k = top1 Then
Hash1(PriveSpace(index).lastpos1) = index + 1
Else
Do While k >= 0 And k <> top1 And k <> k1
k1 = k
k = PriveSpace(k).Pleft1 - 1
Loop
If k = k1 Then
ReHash1
ElseIf k = top1 Then
PriveSpace(k1).Pleft1 = index + 1
End If
End If
k1 = 0
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)
If .Pleft1 > 0 Then
Hash1(.lastpos1) = .Pleft1
.KeyC = 0
.Pleft1 = 0
Else
Hash1(.lastpos1) = 0
.KeyC = 0
End If
End With
toplim = RHS - 1
ReduceHash toplim
Next i
Else
MaxSpace = 5
ReDim PriveSpace(MaxSpace) As item, Hash(MaxSpace * 2 + 3)
ReDim Hash1(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
Dim Parndx1 As Long, ndx2 As Long
If toplim < 0 Then Exit Sub
top1 = toplim
If Find2(RHS, Parndx, ndx) Then
Done = True
index = ndx
If Parndx > -1 Then
PriveSpace(Parndx).Pleft = PriveSpace(ndx).Pleft
Else
Hash(PriveSpace(ndx).lastpos) = PriveSpace(ndx).Pleft
End If
If Find22(PriveSpace(ndx).KeyC, Parndx1, ndx) Then
If ndx = ndx2 Then
With PriveSpace(ndx)
If Parndx1 > -1 Then
If .Pleft1 > 0 Then
Hash1(Parndx1) = .Pleft1
.KeyC = 0
.Pleft1 = 0
Else
Hash1(Parndx1) = 0
.KeyC = 0
End If
Else
If .Pleft1 > 0 Then
Hash1(.lastpos1) = .Pleft1
.KeyC = 0
.Pleft1 = 0
Else
Hash1(.lastpos1) = 0
.KeyC = 0
End If
End If
End With
Else
' something wrong we have here
End If
End If
Dim new_item As item
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
' 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
k1 = 0
k = Hash1(PriveSpace(ndx).lastpos1) - 1
If k = top1 Then
' we have to give the new position to Hash()
Hash1(PriveSpace(ndx).lastpos1) = ndx + 1
Else
Do While k >= 0 And k <> top1 And k <> k1
k1 = k
k = PriveSpace(k).Pleft1 - 1
Loop
If k = k1 Then
ReHash1
ElseIf k = top1 Then
PriveSpace(k1).Pleft1 = ndx + 1
End If
End If
here:
toplim = toplim - 1
ReduceHash toplim
Else
Done = False
End If
End Sub
Property Let Value(KeyC As Currency, RHS As Variant)
Done = False
If index = -1 Then
ItemCreator lastkey, KeyC, RHS
Else
PriveSpace(index).iValue = RHS
End If
Done = True
End Property
Property Set ValueObj(KeyC As Currency, RHS As Variant)
Done = False
If index = -1 Then
ItemCreator lastkey, KeyC, 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 cValue() As Currency
Done = False
If index = -1 Then
Else
Done = True
cValue = PriveSpace(index).sValue2
End If
End Property
Property Let cValue(RHS As Currency)
If index = -1 Then
Else
Done = True
PriveSpace(index).sValue2 = 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(KeyC As Currency) As Variant
Done = False
If index = -1 Then
ElseIf Not IsObject(PriveSpace(index).iValue) Then
Done = True
Value = PriveSpace(index).iValue
If Typename(Value) = "Error" Then
Value = MyVal()
If VarType(Value) = vbString Then Value = PriveSpace(index).Key
End If
End If
End Property
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 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 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(KeyC As Currency) 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
Private Sub ExpandHash()
hashlen = MaxSpace * 2 + 3
ReHash
ReHash1
End Sub
Private Sub ReHashAll()
Dim i As Long
ReDim Hash(hashlen) As Long, Hash1(hashlen) As Long
For i = 0 To toplim
place HashFunc2(i), i
place2 HashFunc22(i), i
Next i
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 Sub ReHash1()
Dim i As Long
ReDim Hash1(hashlen) As Long
For i = 0 To toplim
place2 HashFunc22(i), i
Next i
End Sub
Private Sub ReduceHash(newTop As Long)
If newTop <= 5 Then
If newTop < 0 Then
newTop = -1
toplim = -1
MaxSpace = 5
ReDim PriveSpace(MaxSpace) As item
ReDim Hash(MaxSpace * 2 + 3)
hashlen = MaxSpace * 2 + 3
ElseIf MaxSpace > 40 Then
MaxSpace = 5
ReDim Preserve PriveSpace(MaxSpace) As item
hashlen = MaxSpace * 2 + 3
ReHashAll
End If
Else
If MaxSpace - newTop + 1 > 2 * newTop + 2 Then
MaxSpace = 2 * (newTop + 1) + 1
ReDim Preserve PriveSpace(MaxSpace) As item
hashlen = MaxSpace * 2 + 3
ReHashAll
End If
End If
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)
If Not hashlen = MaxSpace * 2 + 3 Then
hashlen = MaxSpace * 2 + 3
ReHash1
End If
ReHash
ChangeKey = True
Exit Function
End If
k = PriveSpace(k).Pleft - 1
Loop Until k < 0
End If
End Function
Function ChangeKey2(key1 As Currency, Key2 As Currency)
Dim Key As String, NewKey As String
Dim k As Long
If Key2 = 0 Then Key2 = 1
If key1 = Key2 Then ChangeKey2 = True
If ExistSecondKey(Key2) Then Exit Function
k = Hash1(HashFuncC(key1)) - 1
If k >= 0 Then
Do
If PriveSpace(k).KeyC = key1 Then
PriveSpace(k).KeyC = Key2
PriveSpace(k).firsthash1 = HD1(Key2)
If Not hashlen = MaxSpace * 2 + 3 Then
hashlen = MaxSpace * 2 + 3
ReHash
End If
ReHash1
ChangeKey2 = True
Exit Function
End If
k = PriveSpace(k).Pleft1 - 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
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 IsEnum(p As Variant) As Boolean
Dim obj As mHandler
If index = -1 Then
ElseIf IsObject(PriveSpace(index).iValue) Then
If Typename(PriveSpace(index).iValue) = "mHandler" Then
Set obj = PriveSpace(index).iValue
IsEnum = obj.t1 = 4
If IsEnum Then p = obj.index_cursor * obj.sign
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 Find22(KeyC As Currency, Parndx As Long, ndx As Long) As Boolean
Dim k As Long, Key As String, k1 As Long
Parndx = -1
k = Hash1(HashFuncC(KeyC)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).KeyC = KeyC Then Find22 = True: ndx = k: Exit Function
Parndx = k
k1 = k
k = PriveSpace(k).Pleft1 - 1
Loop Until k < 0 Or k1 = k
If k1 = k Then
Parndx = -1
k = Hash(HashFuncC(KeyC)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).KeyC = KeyC Then Find22 = True: ndx = k: Exit Function
Parndx = k
k1 = k
k = PriveSpace(k).Pleft1 - 1
Loop Until k < 0 Or k1 = k
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 ExistSecondKey(KeyC As Currency) As Boolean
Dim k As Long, k1 As Long
If KeyC = 0 Then KeyC = 1
k = Hash1(HashFuncC(KeyC)) - 1
k1 = -2
If k >= 0 Then
Do
If PriveSpace(k).KeyC = KeyC Then ExistSecondKey = True: index = k: Exit Function
k1 = k
k = PriveSpace(k).Pleft1 - 1
Loop Until k < 0 Or k = k1
If k = k1 Then
ReHash1
k = Hash1(HashFuncC(KeyC)) - 1
If k >= 0 Then
Do
If PriveSpace(k).KeyC = KeyC Then ExistSecondKey = True: index = k: Exit Function
k1 = k
k = PriveSpace(k).Pleft1 - 1
Loop Until k < 0 Or k = k1
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(nkey Mod hashlen) - 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, KeyC As Currency, nValue As Variant)
Dim a As Long, kk As Long, kk2 As Long
Done = False
kk = HD(Key)
If KeyC = 0 Then KeyC = 1
kk2 = HD1(KeyC)
If Not AllowSameKey Then If ExistKey2(Key, kk) Then Exit Sub ' done is false
a = Malloc()
With PriveSpace(a)
.Key = Key
.KeyC = KeyC
If IsObject(nValue) Then
Set .iValue = nValue
Else
.iValue = nValue
End If
.firsthash = kk
.firsthash1 = kk2
End With
place kk Mod hashlen, a
place2 kk2 Mod hashlen, a
index = a
Done = True
End Sub
Property Get Percent()
Percent = 100 * count / hashlen
End Property
Private Sub place(b As Long, a As Long)
Dim k As Long
k = Hash(b)
If Not Hash(b) = a + 1 Then
Hash(b) = a + 1
PriveSpace(a).Pleft = k
End If
PriveSpace(a).lastpos = b
End Sub
Private Sub place2(b, ByVal a)
Dim k As Long
k = Hash1(b)
If Not Hash1(b) = a + 1 Then