Digest::FNV - Perl extension for the Fowler/Noll/Vo (FNV) has


Digest-FNV documentation  | view source Contained in the Digest-FNV distribution.

Index


NAME

Top

Digest::FNV - Perl extension for the Fowler/Noll/Vo (FNV) has

SYNOPSIS

Top

  use Digest::FNV qw(fnv fnv32 fnv32a fnv64 fnv64a);

  my $fnv32hash = fnv("abc123");

  my $fnv32hash = fnv32("abc123"); # This does the same as the previous example

  my $hashref = fnv64("abc123");
  $hashref->{bits};     # 32 for 32 bit systems, 64 for 64 bit systems
  $hashref->{upper};    # Upper 32 bits
  $hashref->{lower};    # Lower 32 bits
  $hashref->{bigint}    # use bigint; version of this possibly large number
  $hashref->{longlong}; # 64 bit representation (i.e. (upper << 32) | lower)
                        # This value is useless on 32 bit systems

DESCRIPTION

Top

FNV is a hashing algorithm for short to medium length strings. It is best suited for strings that are typically around 1024 bytes or less (URLs, IP addresses, hostnames, etc). This implementation is based on the code provided by Landon Curt Noll.

There are two slightly different algorithms. One is called FNV-1, and the other is FNV-1a. Both algorithms are provided for each of 32 and 64 bit hash values.

For full information on this algorithm please visit http://isthe.com/chongo/tech/comp/fnv/

The original Digest::FNV was written by Tan D Nguyen <tnguyen@cpan.org>. This version is a drop-in replacement (all existing code should continue to work). However, it is a complete rewrite.

This new version works on both 32 and 64 bit platforms.

CAVEATS

Top

Part of the challenge of supporting this module are the differences between 32-bit and 64-bit architectures.

In practice the values returned by these algorithms are often further processed (further algorithms). It is for that reason that the nature of what the fnv64/fnv64a functions return is exposed. When trying to support both 64 and 32 bit architectures it is necessary.

You cannot rely on only $hashref->{bigint} if you plan to perform and further math on that value on 32 bit systems. You also cannot rely on $hashref->{longlong} unless you know the architecture.

This module attempts to provide all of the necessary information to arrive at a true 64-bit value. Often times you're passing values to other software (a database, for example), and that database probably provides 64-bit left shift operations.

ACKNOWLEDGEMENTS

Top

Tan D Nguyen <tnguyen@cpan.org> who wrote the first Digest::FNV module.

The C code was based on the public domain FNV sources released by Landon Curt Noll (see below).

SEE ALSO

Top

http://isthe.com/chongo/tech/comp/fnv/ http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash

AUTHOR

Top

Jeffrey Webster, <jeff.webster@zogmedia.com>

COPYRIGHT AND LICENSE

Top


Digest-FNV documentation  | view source Contained in the Digest-FNV distribution.