We use hash tables quite often in AutoIt. Be it the Scripting.Dictionary object or now the built-in AutoIt maps.
But using something is still a difference to understanding how these data structures work internally.
To make this more understandable for me I thought: What could be more obvious than implementing my own hash table in AutoIt?
The result is this UDF.
So if you want to understand for yourself how hash tables work exactly, you can have a close look at them in familiar AutoIt code.
For productive purposes the UDF is of course rather not intended, because the alternatives Scripting.Dictionary and AutoIt-Maps offer more.
Only from a very large number of elements (~ 1,000,000 elements) this UDF could be faster than the AutoIt maps.
How to use the hash table?: example #1:
#include "hashtable.au3"
#include "Array.au3"
Global $aTable = _hashtable_Create()
_hashtable_Add($aTable, "banana", "the value of banana")
_hashtable_Add($aTable, "apple", "the value of apple")
_hashtable_Add($aTable, "apricot", "the value of apricot")
_hashtable_Add($aTable, "orange", "the value of orange")
; remove element:
_hashtable_Remove($aTable, "apple")
; get value with key:
$value = _hashtable_Get($aTable, "apricot")
MsgBox(0, "value for: apricot", $value)
; get the Keys as an array
$aKeys = _hashtable_getKeys($aTable)
_ArrayDisplay($aKeys, "The keys of the hash-table", "", 64)
; get the values as an array
$aValues = _hashtable_getValues($aTable)
_ArrayDisplay($aValues, "The values of the hash-table", "", 64)
example #2:
#include "hashtable.au3"
#include "Array.au3"
Global $aTable = _hashtable_Create()
For $i = 1 To 10000
_hashtable_Add($aTable, "element " & Random(1, 1000, 1), "test-string " & $i)
Next
; get the Keys as an array
$aKeys = _hashtable_getKeys($aTable)
; get the values as an array
$aValues = _hashtable_getValues($aTable)
; get all key-value pairs
$aKeyValues = _hashtable_getKeyValues($aTable)
_ArrayDisplay($aKeyValues)
hashtable.au3