Skip to content

I implemented mzHash64 in pure Perl #1

@scottchiefbaker

Description

@scottchiefbaker

Took some work, but I implement mzHash64 in pure Perl.

sub mzhash64 {
    my ($input, $seed) = @_;
    $seed ||= 0;

    my $hash = (16327758955582512922 ^ $seed);

    use bytes;
    for (my $i = 0; $i < length($input); $i++) {
        my $char = substr($input, $i, 1);

        use integer;
        my $chunk1 = (12889002000335424835 * ($i + ord($char)));
        no integer;
        my $chunk2 = ($hash << 2) ^ ($hash >> 2);

        $hash = $chunk1 ^ $chunk2;
    }
    no bytes;

    return $hash;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions