-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHashList.cls
More file actions
710 lines (683 loc) · 21.3 KB
/
Copy pathHashList.cls
File metadata and controls
710 lines (683 loc) · 21.3 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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "HashList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Private Const vbLongLong = 20
Private maxlonglong, limitlonglong
Private Declare Function HashData Lib "shlwapi" (ByVal straddr As Long, ByVal ByteSize As Long, ByVal res As Long, ByVal ressize As Long) As Long
Private HasHandlers As Boolean
Private mem As New refArray
Private hashsize As Integer
Private p As Long, nextVal As Long, datasize As Long, hashmod As Long, lastDataSize As Long
Private Const keyArray = 1, DataArray = 2, HashArray = 0, FirstKey = 3, Pleft = 4, HashSizeStore = 5, nextValStore = 6
Sub Prepare(ByVal Prefdatasize As Long, Optional HandlersOnly) ' Optional
If mem.Elements(p) = 0 Then
datasize = Prefdatasize
lastDataSize = datasize
HasHandlers = Not IsMissing(HandlersOnly)
hashmod = CLng(datasize * 1.5)
If datasize < 150 Then
hashsize = 1
ElseIf datasize < 21500 Then
hashsize = 2
Else
hashsize = 4
End If
End If
End Sub
Function MyIsNumeric(v As Variant) As Boolean
Dim n As Byte
n = MemByte(VarPtr(v))
If n < 2 Then Exit Function
If n <= 5 Then MyIsNumeric = True
End Function
Function Add(val, bkey, Optional thistype) As Long
If HasHandlers Then Err.Raise "Only Handlers Support"
Dim akey
If MyIsNumeric(bkey) Then bkey = CLng(bkey)
If VarType(bkey) <> vbLong And VarType(bkey) <> vbString Then Err.Raise 5
If mem.Count = 0 Then
If datasize = 0 Then datasize = 10: lastDataSize = datasize: hashmod = CLng(datasize * 1.5)
If hashsize = 0 Then hashsize = 1
Select Case hashsize
Case 1
mem.DefArrayAt Pleft, vbByte, datasize
mem.DefArrayAt FirstKey, vbByte, datasize
mem.DefArrayAt HashArray, vbByte, hashmod
Case 2
mem.DefArrayAt Pleft, vbInteger, datasize
mem.DefArrayAt FirstKey, vbInteger, datasize
mem.DefArrayAt HashArray, vbInteger, hashmod
Case 4
mem.DefArrayAt Pleft, vbLong, datasize
mem.DefArrayAt FirstKey, vbLong, datasize
mem.DefArrayAt HashArray, vbLong, hashmod
End Select
mem.DefArrayAt keyArray, vbString, datasize
mem(HashSizeStore) = hashsize
If IsMissing(thistype) Then
Select Case VarType(val)
Case vbLong, vbInteger, vbSingle, vbCurrency, vbString, vbByte, vbDate, vbLongLong, vbDecimal, vbObject, vbDataObject
mem.DefArrayAt DataArray, VarType(val), datasize
Case Else
mem.DefArrayAt DataArray, vbVariant, datasize
End Select
Else
mem.DefArrayAt DataArray, thistype, datasize
End If
nextVal = -1
ElseIf datasize = 0 Then
datasize = mem.Count(Pleft)
lastDataSize = datasize
hashmod = mem.Count(HashArray)
hashsize = mem(HashSizeStore)
nextVal = mem(nextValStore)
End If
If nextVal >= datasize Then
datasize = datasize * 2
lastDataSize = datasize
Select Case hashsize
Case 1
If datasize < 150 Then
ReHashByte
Else
ReHash2
End If
Case 2
If datasize < 21500 Then
ReHashInteger
Else
ReHash4
End If
Case Else
ReHashLong
End Select
End If
nextVal = nextVal + 1
mem(nextValStore) = nextVal
If VarType(bkey) = vbLong Then
akey = space$(2)
MemLong(StrPtr(akey)) = bkey
Else
SwapVariant akey, bkey
End If
mem(keyArray, nextVal) = akey
mem(DataArray, nextVal) = val
Dim pv As Long, pv1 As Integer, pv2 As Byte
pv = mem.Hash(keyArray, nextVal, hashsize)
Select Case hashsize
Case 1
pv2 = MemByte(VarPtr(pv)) And CByte(127)
mem(FirstKey, nextVal) = pv2
pv = pv2 Mod hashmod
Case 2
pv1 = MemInt(VarPtr(pv)) And &H7FFF
mem(FirstKey, nextVal) = pv1
pv = pv1 Mod hashmod
Case Else
pv = pv And &H7FFFFFFF
mem(FirstKey, nextVal) = pv
pv = pv Mod hashmod
End Select
If pv = 0 Then pv = 1
Dim K
K = mem(HashArray, pv)
If Not K = nextVal + 1 Then
mem(HashArray, pv) = nextVal + 1
mem(Pleft, nextVal) = K
Add = nextVal
End If
End Function
Function AddHandler(akey As String) As Long
If mem.Count = 0 Then
HasHandlers = True
If datasize = 0 Then datasize = 10: lastDataSize = datasize: hashmod = CLng(datasize * 1.5)
If hashsize = 0 Then hashsize = 1
Select Case hashsize
Case 1
mem.DefArrayAt Pleft, vbByte, datasize
mem.DefArrayAt FirstKey, vbByte, datasize
mem.DefArrayAt HashArray, vbByte, hashmod
Case 2
mem.DefArrayAt Pleft, vbInteger, datasize
mem.DefArrayAt FirstKey, vbInteger, datasize
mem.DefArrayAt HashArray, vbInteger, hashmod
Case 4
mem.DefArrayAt Pleft, vbLong, datasize
mem.DefArrayAt FirstKey, vbLong, datasize
mem.DefArrayAt HashArray, vbLong, hashmod
End Select
mem.DefArrayAt keyArray, vbString, datasize
mem(HashSizeStore) = hashsize
nextVal = -1
ElseIf datasize = 0 Then
HasHandlers = True
mem(DataArray) = Empty
lastDataSize = datasize
datasize = mem.Count(Pleft)
hashmod = mem.Count(HashArray)
hashsize = mem(HashSizeStore)
nextVal = mem(nextValStore)
Else
If Not HasHandlers Then Err.Raise "Use Prepare first to use Handlers"
End If
If nextVal >= datasize Then
datasize = datasize * 2
lastDataSize = datasize
Select Case hashsize
Case 1
If datasize < 150 Then
ReHashByte
Else
ReHash2
End If
Case 2
If datasize < 21500 Then
ReHashInteger
Else
ReHash4
End If
Case Else
ReHashLong
End Select
End If
nextVal = nextVal + 1
mem(nextValStore) = nextVal
mem(keyArray, nextVal) = akey
Dim pv As Long, pv1 As Integer, pv2 As Byte
pv = mem.Hash(keyArray, nextVal, hashsize)
Select Case hashsize
Case 1
pv2 = MemByte(VarPtr(pv)) And CByte(127)
mem(FirstKey, nextVal) = pv2
pv = pv2 Mod hashmod
Case 2
pv1 = MemInt(VarPtr(pv)) And &H7FFF
mem(FirstKey, nextVal) = pv1
pv = pv1 Mod hashmod
Case Else
pv = pv And &H7FFFFFFF
mem(FirstKey, nextVal) = pv
pv = pv Mod hashmod
End Select
'If pV = 0 Then pV = 1
Dim K
K = mem(HashArray, pv)
If Not K = nextVal + 1 Then
mem(HashArray, pv) = nextVal + 1
mem(Pleft, nextVal) = K
AddHandler = nextVal
End If
End Function
Function Find(bkey, Optional v, Optional where, Optional queue) As Boolean
If HasHandlers Then Err.Raise "Only Handlers Support"
Dim findfirst As Boolean
findfirst = True
If datasize = 0 Then
datasize = mem.Count(Pleft)
lastDataSize = datasize
hashmod = mem.Count(HashArray)
hashsize = mem(HashSizeStore)
nextVal = mem(nextValStore)
End If
If Not IsMissing(queue) Then
If Not IsNumeric(queue) Then Exit Function
If queue > 0 And queue < nextVal Then findfirst = False
End If
If VarType(bkey) <> vbLong And VarType(bkey) <> vbString Then Err.Raise 5
Dim akey As String
If VarType(bkey) = vbLong Then
akey = space$(2)
MemLong(StrPtr(akey)) = bkey
Else
akey = bkey
End If
Dim K As Long
If findfirst Then
Dim pv As Long, pv1 As Integer, pv2 As Byte
pv = HashkEY(akey, hashsize)
If pv = 0 Then Exit Function
Select Case hashsize
Case 1
pv2 = MemByte(VarPtr(pv)) And CByte(127)
pv = pv2 Mod hashmod
Case 2
pv1 = MemInt(VarPtr(pv)) And &H7FFF
pv = pv1 Mod hashmod
Case Else
pv = pv And &H7FFFFFFF
pv = pv Mod hashmod
End Select
If pv = 0 Then pv = 1
K = mem(HashArray, pv)
If K = 0 Then Exit Function
K = K - 1
If mem.CompareStrEq(keyArray, K, akey) Then
If Not IsMissing(v) Then
If mem.vtType(DataArray, K) = 9 Then
Set v = mem.Value(DataArray, K)
Else
v = mem(DataArray, K)
End If
End If
If Not IsMissing(where) Then where = K
If Not IsMissing(queue) Then queue = mem(Pleft, K)
Find = True
Else
K = mem(Pleft, K) - 1
jump1:
Do While K >= 0
If mem.CompareStrEq(keyArray, K, akey) Then
If Not IsMissing(v) Then
If mem.vtType(DataArray, K) = 9 Then
Set v = mem.Value(DataArray, K)
Else
v = mem(DataArray, K)
End If
End If
If Not IsMissing(where) Then where = K
If Not IsMissing(queue) Then queue = mem(Pleft, K)
Find = True
Exit Function
End If
queue = Empty
K = mem(Pleft, K) - 1
Loop
End If
Else
K = CLng(queue) - 1
GoTo jump1
End If
End Function
Function FindHandler(akey As String, hashcode As Long, Handler As Long) As Boolean
If datasize = 0 Then
datasize = mem.Count(Pleft)
lastDataSize = datasize
hashmod = mem.Count(HashArray)
hashsize = mem(HashSizeStore)
nextVal = mem(nextValStore)
End If
Dim K As Long
Dim pv As Long, pv1 As Integer, pv2 As Byte
pv = HashkEY(akey, hashsize)
Select Case hashsize
Case 1
pv2 = MemByte(VarPtr(pv)) And CByte(127)
pv = pv2 Mod hashmod
Case 2
pv1 = MemInt(VarPtr(pv)) And &H7FFF
pv = pv1 Mod hashmod
Case Else
pv = pv And &H7FFFFFFF
pv = pv Mod hashmod
End Select
If pv = 0 Then pv = 1
K = mem(HashArray, pv)
If K = 0 Then Exit Function
K = K - 1
If mem.CompareStrEq(keyArray, K, akey) Then
Handler = K
hashcode = mem(FirstKey, K)
FindHandler = True
Exit Function
End If
End Function
Property Get Keys()
Keys = mem(keyArray)
End Property
Property Get Values()
Values = mem(DataArray)
End Property
Property Set Value(ByVal where As Long, RHS)
If HasHandlers Then Exit Property
If where < 0 Or where > mem.Count(DataArray) Then Exit Property
mem(DataArray, where) = RHS
End Property
Property Let Value(ByVal where As Long, RHS)
If HasHandlers Then Exit Property
If where < 0 Or where > mem.Count(DataArray) Then Exit Property
mem(DataArray, where) = RHS
End Property
Property Get Value(ByVal where As Long)
Attribute Value.VB_UserMemId = 0
Dim ret
If Not HasHandlers Then
If where < 0 Or where > mem.Count(DataArray) Then Exit Property
If mem.vtType(DataArray, where) = 9 Then
Set ret = mem.Value(DataArray, where)
SwapVariant ret, Value
Else
Value = mem(DataArray, where)
End If
Else
If where < 0 Or where > nextVal Then Value = False Else Value = True
End If
End Property
Property Let Key(ByVal where As Long, bkey)
If HasHandlers Then Err.Raise "Only Handlers Support"
Dim akey As String
If MyIsNumeric(bkey) Then
akey = space$(2)
MemLong(StrPtr(akey)) = bkey
Else
akey = bkey
End If
Dim pv As Long, pv1 As Integer, pv2 As Byte
mem(keyArray, where) = akey
pv = mem.Hash(keyArray, where, hashsize)
Select Case hashsize
Case 1
pv2 = MemByte(VarPtr(pv)) And CByte(127)
mem(FirstKey, where) = pv2
Case 2
pv1 = MemInt(VarPtr(pv)) And &H7FFF
mem(FirstKey, where) = pv1
Case Else
pv = pv And &H7FFFFFFF
mem(FirstKey, where) = pv
End Select
Rehash
End Property
Property Let KeyNoReHash(ByVal where As Long, bkey)
If HasHandlers Then Err.Raise "Only Handlers Support"
Dim akey As String
If MyIsNumeric(bkey) Then
akey = space$(2)
MemLong(StrPtr(akey)) = bkey
Else
akey = bkey
End If
Dim pv As Long, pv1 As Integer, pv2 As Byte
mem(keyArray, where) = akey
pv = mem.Hash(keyArray, where, hashsize)
Select Case hashsize
Case 1
pv2 = MemByte(VarPtr(pv)) And CByte(127)
mem(FirstKey, where) = pv2
Case 2
pv1 = MemInt(VarPtr(pv)) And &H7FFF
mem(FirstKey, where) = pv1
Case Else
pv = pv And &H7FFFFFFF
mem(FirstKey, where) = pv
End Select
End Property
Property Get Key(ByVal where As Long)
If where < 0 Or where > mem.Count(DataArray) Then Exit Property
Key = mem(keyArray, where)
End Property
Friend Property Set PlaceRefArray(that As refArray)
Set mem = that.Copy()
datasize = 0
lastDataSize = datasize
End Property
Property Get Copy() As HashList
Set Copy = New HashList
If HasHandlers Then Copy.Prepare 0, HasHandlers
Set Copy.PlaceRefArray = mem
End Property
Property Get HashkEY(Key$, Optional ByVal Size As Long = 4) As Long
If Size < 1 Then Exit Property
If LenB(Key$) = 0 Then
HashkEY = 1
Else
HashData StrPtr(Key$), LenB(Key$), VarPtr(HashkEY), Size
End If
End Property
Property Get Count()
If datasize = 0 Then
datasize = mem.Count(Pleft)
lastDataSize = datasize
hashmod = mem.Count(HashArray)
hashsize = mem(HashSizeStore)
nextVal = mem(nextValStore) = nextVal
End If
Count = nextVal + 1
End Property
Sub Clear()
Set mem = New refArray
datasize = 0
lastDataSize = datasize
End Sub
Function KeyNumeric(akey) As Long
If VarType(akey) <> vbString Then Err.Raise 5
If Len(akey) = 2 Then
KeyNumeric = MemLong(StrPtr(akey))
End If
End Function
Property Get KeyNum(ByVal where As Long) As Long
If where < 0 Or where > mem.Count(DataArray) Then Exit Property
KeyNum = KeyNumeric(mem(keyArray, where))
End Property
Property Get KeyNum2(where As Long) As Long
If where < 0 Or where > mem.Count(DataArray) Then Exit Property
KeyNum2 = KeyNumeric(mem(keyArray, where)) And &HFFFF&
End Property
Sub SwapVariant(ByRef a As Variant, ByRef b As Variant)
Static t(0 To 3) As Long ' 4 Longs * 4 bytes each = 16 bytes
MemCopy VarPtr(t(0)), ByVal VarPtr(a), 16
MemCopy VarPtr(a), VarPtr(b), 16
MemCopy VarPtr(b), VarPtr(t(0)), 16
End Sub
Private Sub ReHashByte()
mem(HashArray) = Empty
If lastDataSize <> datasize Then ' lastDataSize = datasize when we change a key (the name of key).
mem(FirstKey, datasize) = CByte(0)
mem(Pleft, datasize) = CByte(0)
mem(keyArray, datasize) = ""
End If
If Not HasHandlers Then
mem(DataArray, datasize) = mem(DataArray, 0)
End If
hashmod = CLng(datasize * 1.5)
mem.DefArrayAt HashArray, vbByte, hashmod
Dim pv As Long, K As Byte, I As Byte
For I = 0 To Count - 1
pv = mem(FirstKey, I) Mod hashmod
K = mem(HashArray, pv)
'If Not k = i + 1 Then
mem(HashArray, pv) = I + 1
mem(Pleft, I) = K
'End If
Next I
End Sub
Private Sub ReHashInteger()
mem(HashArray) = Empty
If lastDataSize <> datasize Then
mem(FirstKey, datasize) = 0
mem(Pleft, datasize) = 0
mem(keyArray, datasize) = ""
End If
If Not HasHandlers Then
mem(DataArray, datasize) = mem(DataArray, 0)
End If
hashmod = CLng(datasize * 1.5)
mem.DefArrayAt HashArray, vbInteger, hashmod
Dim pv As Long, K As Integer, I As Integer
For I = 0 To Count - 1
pv = mem(FirstKey, I) Mod hashmod
K = mem(HashArray, pv)
'If Not k = i + 1 Then
mem(HashArray, pv) = I + 1
mem(Pleft, I) = K
'End If
Next I
End Sub
Private Sub ReHashLong()
mem(HashArray) = Empty
If lastDataSize <> datasize Then
mem(FirstKey, datasize) = 0&
mem(Pleft, datasize) = 0&
mem(keyArray, datasize) = ""
End If
hashmod = CLng(datasize * 1.5)
mem.DefArrayAt HashArray, vbLong, hashmod
If Not HasHandlers Then
mem(DataArray, datasize) = mem(DataArray, 0)
End If
Dim pv As Long, K As Long, I As Long
For I = 0 To Count - 1
pv = mem(FirstKey, I) Mod hashmod
K = mem(HashArray, pv)
'If Not k = i + 1 Then ' these was for security..
mem(HashArray, pv) = I + 1
mem(Pleft, I) = K
'End If
Next I
End Sub
Private Sub ReHash2()
Dim pv As Long, K As Integer, I As Integer
Dim pv1 As Integer
hashsize = 2
mem(HashSizeStore) = hashsize
mem(HashArray) = Empty
mem(FirstKey) = Empty
mem(Pleft) = Empty
hashmod = CLng(datasize * 1.5)
mem.DefArrayAt Pleft, vbInteger, datasize
mem.DefArrayAt FirstKey, vbInteger, datasize
mem.DefArrayAt HashArray, vbInteger, hashmod
mem(keyArray, datasize) = ""
If Not HasHandlers Then
mem(DataArray, datasize) = mem(DataArray, 0)
End If
For I = 0 To Count - 1
p = mem.Hash(keyArray, CLng(I), hashsize)
pv1 = MemInt(VarPtr(p)) And &H7FFF
mem(FirstKey, I) = pv1
pv = pv1 Mod hashmod
K = mem(HashArray, pv)
'If Not k = i + 1 Then
mem(HashArray, pv) = I + 1
mem(Pleft, I) = K
'End If
Next I
End Sub
Private Sub ReHash4()
Dim pv As Long, K As Long, I As Long
Dim pv2 As Long
hashsize = 4
mem(HashSizeStore) = hashsize
mem(HashArray) = Empty
mem(FirstKey) = Empty
mem(Pleft) = Empty
hashmod = CLng(datasize * 1.5)
mem.DefArrayAt Pleft, vbLong, datasize
mem.DefArrayAt FirstKey, vbLong, datasize
mem.DefArrayAt HashArray, vbLong, hashmod
mem(keyArray, datasize) = ""
If Not HasHandlers Then
mem(DataArray, datasize) = mem(DataArray, 0)
End If
For I = 0 To Count - 1
pv2 = mem.Hash(keyArray, I, hashsize)
pv2 = pv2 And &H7FFFFFFF
mem(FirstKey, I) = pv2
pv = pv2 Mod hashmod
K = mem(HashArray, pv)
'If Not k = i + 1 Then
mem(HashArray, pv) = I + 1
mem(Pleft, I) = K
'End If
Next I
End Sub
Sub Rehash()
If Count > 0 Then
Select Case hashsize
Case 1
ReHashByte
Case 2
ReHashInteger
Case Else
ReHashLong
End Select
End If
End Sub
Function Initialized(p) As Boolean
Initialized = mem.Elements(p) > 0
End Function
Sub SwapStrings(a$, b$)
Dim I As Long, j As Long
I = MemLong(VarPtr(a$))
j = MemLong(VarPtr(b$))
MemLong(VarPtr(a$)) = j
MemLong(VarPtr(b$)) = I
End Sub
Public Function create(ParamArray v()) As HashList
Dim hl As New HashList, I As Long
Dim pp() As Variant
pp = v
If mem.Elements(pp) > 0 Then
For I = 0 To mem.Elements(pp) - 1
hl.Add CVar(pp(I)), I + 1, vbVariant
Next I
End If
Set create = hl
End Function
Public Function cInt64(p)
Static maxlonglong, limitlonglong, OneLongLong, OneBigLongLong
Dim a, I As Integer
If MemInt(VarPtr(maxlonglong)) = 0 Then
maxlonglong = CDec("18446744073709551616")
limitlonglong = CDec("9223372036854775808")
MemInt(VarPtr(OneLongLong)) = 20
MemByte(VarPtr(OneLongLong) + 8) = 1
MemInt(VarPtr(OneBigLongLong)) = 20
MemByte(VarPtr(OneBigLongLong) + 12) = 1
End If
I = MemInt(VarPtr(p))
Select Case I
Case vbDecimal
a = Fix(p)
a = a - Int(a / maxlonglong) * maxlonglong
If a < -limitlonglong - 1 Then
While a <= -limitlonglong - 1: a = a + maxlonglong: Wend
End If
While a >= limitlonglong: a = a - maxlonglong: Wend
cInt64 = -OneLongLong And a
Case 20
cInt64 = p
Case vbLong, vbInteger
cInt64 = -OneLongLong And p
Case Else
On Error GoTo er1
a = Fix(CDec(p))
If a > limitlonglong Or a <= -limitlonglong Then
a = a - Int(a / (maxlonglong)) * (maxlonglong)
If a <= -limitlonglong - 1 Then
While a <= -limitlonglong - 1: a = a + maxlonglong: Wend
End If
While a >= limitlonglong: a = a - maxlonglong: Wend
End If
cInt64 = -OneLongLong And a
If I = vbString Then
If Left$(p, 1) = "&" And a < 0 Then
Select Case Len(p)
Case 10
If InStr("89ABCDEF", UCase(Mid$(p, 3, 1))) > 0 Then
cInt64 = OneBigLongLong + cInt64
End If
Case 18
If Mid$(p, 3, 8) = "00000000" Then
cInt64 = OneBigLongLong + cInt64
End If
Case 11 To 17
If cInt64 < 0 Then cInt64 = OneBigLongLong + cInt64
End Select
End If
End If
End Select
Exit Function
er1:
cInt64 = OneLongLong - OneLongLong
End Function