Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created August 2, 2010 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/505260 to your computer and use it in GitHub Desktop.
Save tadzik/505260 to your computer and use it in GitHub Desktop.
module Digest::djb2;
sub hash(Buf $input) is export {
my Int $hash = 5381; # 5381 is one of two 'magic numbers' used in this algorithm
for 0..$input.elems-1 {
$hash = (($hash +< 5) + $hash) + $input[$_]; # 33 is second
}
return $hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment