Last active
September 11, 2021 03:59
-
-
Save thejsj/481602b414c2f8defd03d41a23c255d8 to your computer and use it in GitHub Desktop.
Pearson Hashing Function
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
'use strict' | |
// Ideally, this table would be shuffled... | |
// 256 will be the highest value provided by this hashing function | |
let table = [...new Array(256)].map((_, i) => i) | |
const hash8 = (message, table) => { | |
return message.split('').reduce((hash, c) => { | |
return table[(hash + c.charCodeAt(0)) % (table.length - 1)] | |
}, message.length % (table.length - 1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment