The keys are strings and there is a sub that calculates their hash code.
Which of the following alternative hashes will work properly and which won't:
A.
B4X:
Private Sub CalcHash (key As String) As Int
Return key.Length
End Sub
B.
B4X:
Private Sub CalcHash (key As String) As Int
Return -5
End Sub
C.
B4X:
Private Sub CalcHash (key As String) As Int
Dim h As Int = Rnd(0, 1000)
For i = 0 To key.Length - 1
h = Bit.ShiftLeft(h, 5) + h + Asc(key.CharAt(i))
Next
Return h
End Sub
D.
B4X:
Private Sub CalcHash (key As String) As Int
key = key.ToLowerCase
Dim h As Int = 5338
For i = 0 To key.Length - 1
h = Bit.ShiftLeft(h, 5) + h + Asc(key.CharAt(i))
Next
Return h
End Sub
Not exactly.
The hash number is used to directly find the relevant bucket. (Almost) no searching is done. The average complexity of hash table is O(1) unlike the complexity of searching a list which is O(n).
I don't think that it will be inefficient because of this. You can make a test and check the number of collisions.
I tried to confuse by lowering the case of the key. This of course doesn't make the hash table case insensitive.