Created
June 9, 2020 01:19
-
-
Save atoponce/777ceed27e20e7b3598f9df37f9a6657 to your computer and use it in GitHub Desktop.
15-bit Pearson hash function for LibreOffice Calc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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