|
-
Sep 4th, 2016, 06:31 AM
#11
Re: Simple and fast, lightweight HashList-Class (no APIs)
As for "the crash" ... I tried my best to reproduce it (unsuccessfully), but changed the return-values of .Items() and Keys()
to a normal Variant-Container now anyways (in my opinion there's a good chance, that the crash has more to do with your
Assembly-stuff, sitting in the same project).
- no, it is not a full replacement for the MS-Dictionary (for that you will have to change your Item-Prop-Implementation)
What do you mean?
- and no, it is only partly an example to serve as "VB-Code being faster than C" because it is quite an amount slower than the MS-Dictionary in Binary-Comparemode.
I can bet with you. This is another test:
Code:
Option Explicit
Private Declare Function QueryPerformanceFrequency Lib "kernel32" ( _
ByRef lpFrequency As Any) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" ( _
ByRef lpPerformanceCount As Any) As Long
Dim d As Dictionary
Dim t As clsTrickHashTable
Private Sub Form_Load()
Dim index As Long
Dim cFreq As Currency
Dim cVal As Currency
Dim time As Currency
Dim tDic As Currency
Dim tTrick As Currency
Dim sKeys() As String
MakeRandomKeys sKeys()
QueryPerformanceFrequency cFreq
Set d = New Dictionary
Set t = New clsTrickHashTable
' // Check binary compare
t.CompareMode = BinaryCompare
d.CompareMode = BinaryCompare
QueryPerformanceCounter time
For index = 0 To UBound(sKeys)
d.Add sKeys(index) & index, Me
Next
QueryPerformanceCounter tDic: tDic = tDic - time
QueryPerformanceCounter time
For index = 0 To UBound(sKeys)
t.Add sKeys(index) & index, Me
Next
QueryPerformanceCounter tTrick: tTrick = tTrick - time
MsgBox "Dictionary: " & (tDic / cFreq) * 1000 & " ms." & vbNewLine & _
"TrickHashTable: " & (tTrick / cFreq) * 1000 & " ms." & vbNewLine
End Sub
Private Sub MakeRandomKeys( _
ByRef sKeys() As String)
Dim index As Long
Dim lLen As Long
Dim char As Integer
ReDim sKeys(500000)
For index = 0 To UBound(sKeys)
lLen = Int(Rnd * 50) + 10
Do While lLen
char = Int(Rnd * 62)
Select Case char
Case Is < 10: char = char + 48
Case Is < 36: char = char + 55
Case Else: char = char + 61
End Select
sKeys(index) = sKeys(index) & Chr$(char)
lLen = lLen - 1
Loop
Next
End Sub
On my computer Windows 7 x64 SP1 AMD Athlon(tm) II X2 245 2.90 Ghz 6GB RAM:
---------------------------
Project1
---------------------------
Dictionary: 24905,1339625567 ms.
TrickHashTable: 15037,1265761431 ms.
---------------------------
ОК
---------------------------
Overall (mine and yours tests) both Dictionary and TrickHashTable work identically with Binary compare mode (however i wrote so in the original topic):
Run fast enough on my computer about as well (even a bit faster) as a dictionary with binary comparison...
With Text compare mode my class works faster than Dictionary.
- no, my For Each (over the Keys) did the same as yours (since your Class was saying: hsh.EnumMode = ENUM_BY_KEY = True)
No, you enumerated String keys. Mine Variant, ie. any Object, Boolean, String, etc. simultaneously.
the difference is that you claim that to be the case, whereas I did not. I said "roughly compatible"
Then why did you compare our classes? Maybe i'm wrong but you didn't say why my class isn't FULL compatible with MS Dictionary. Please tell me then i make it full compatible.
- my aim is, to cover about 90% of the use-cases (and no, the .Remove-Single-Item call is not among those)
The controversial statement, my class is replacement of MS Dictionary. Dictionary/Collection contains Remove method.
- with a bit of additional work, you could make yours probably 99% compatible - maybe even 100%
Please tell me what should i add in order to make full compatibility.
Nevertheless, one can throw all three Class-Types into a real-world project - and use them there without
changing the code (much). In most cases only the ClassVariable-Definitions have to be changed (type-wise).
Okay, if you compare our classes and MS Dictionary you should suggest alternative. Your class isn't alternative. You can add 100 arrays with different keys types, but it won't be replacement.
since you made it a topic here
You became to compare our classes.
About your test. Your class don't support different keys types (like TrickHashTable, Dictionary). For example if i want to have associate an object with other object i can't do it through your class. Of course you can say "my class shouldn't support it" - okay, then don't compare them:
Your HashTable-Class-Implementation is not really an alternative to cHashD in either regard
I can also write same.
Regarding,
Krivous Anatoly (The trick)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|