Skip to content

Instantly share code, notes, and snippets.

@atoponce
Created June 9, 2020 01:19
Show Gist options
  • Save atoponce/777ceed27e20e7b3598f9df37f9a6657 to your computer and use it in GitHub Desktop.
Save atoponce/777ceed27e20e7b3598f9df37f9a6657 to your computer and use it in GitHub Desktop.
15-bit Pearson hash function for LibreOffice Calc
' REM 15-bit Pearson Hash, because I can't figure out 32-bits for FNV-1a
Function Hash(strText as String) as Long
Dim h As Long
Dim nextChar As String
Dim temp As Long
Dim table(0 To 32767) as Long
Dim seed as Long
seed = 1
h = len(strText) MOD 32768
For i = 0 to 32767
' Shuffle the table with a Linear congruential generator.
seed = (5*seed + 16385) MOD 32768
table(i) = seed
Next i
For i = 1 To Len(strText)
nextChar = Mid(strText, i, 1)
h = table(h XOR Asc(NextChar))
Next i
Hash = h
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment