Structure pair
Key.s
Value.l
Belegt.b
EndStructure
start=ElapsedMilliseconds()
Global Mapsize.l=100000
Global Dim map.pair(Mapsize+1);
Procedure.l GetHash(InKey.s);
Protected hash= CRC32Fingerprint(@InKey,StringByteLength(InKey))%mapsize
ProcedureReturn Abs(hash)
EndProcedure
Procedure Add(Key.s, Value.l)
Protected Hash.l
Hash=GetHash(Key.s)
Repeat
If map(hash)\Belegt=#False
map(hash)\Key=Key
map(hash)\Value=Value
map(hash)\Belegt=#True
ProcedureReturn
Else
hash=(hash+1)%mapsize
EndIf
ForEver
EndProcedure
Procedure Get(Key.s)
Protected Hash.l
Hash=GetHash(Key.s)
Repeat
If map(hash)\Belegt=#False
ProcedureReturn 0
ElseIf map(hash)\key=key
ProcedureReturn map(hash)\Value
Else
hash=(hash+1)%mapsize
EndIf
ForEver
EndProcedure
For k = 0 To 9000
Add(Str(k),k)
Next
For k = 0 To 9000
Get(Str(k))
Next
Debug ElapsedMilliseconds()-start
;-----------------------------------------------------
start=ElapsedMilliseconds()
NewList test.pair()
For t = 0 To 9000
AddElement(test())
test()\value=t
test()\key=Str(t)
Next
For t = 0 To 9000
S.s=Str(t)
ForEach test()
If test()\key=S
Break
EndIf
Next
Next
Debug ElapsedMilliseconds()-start
...but the comparison is like "apples vs. pears"...
These data-structures do have totally different qualities, as well as arrays, trees, stacks or heaps do have their individual pro and contra.