Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Last active July 9, 2019 01:34
Show Gist options
  • Save kiinlam/7300804b1de908d24574635a9a1d0331 to your computer and use it in GitHub Desktop.
Save kiinlam/7300804b1de908d24574635a9a1d0331 to your computer and use it in GitHub Desktop.
哈希函数,Daniel J.Bernstein 教授发明的,是目前公布的最有效的哈希函数
public long DJBHash(String str)
{
long hash = 5381;
for(int i = 0; i < str.length(); i++)
{
hash = ((hash << 5) + hash) + str.charAt(i);
}
return hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment