Algorithm-Nhash

 view release on metacpan or  search on metacpan

lib/Algorithm/Nhash.pm  view on Meta::CPAN

 # prints '417' (which is 6*64+33)
 exim4 -be '${nhash_512:supercalifragilisticexpialidocious}'

=head1 DESCRIPTION

This is an implementation of the Exim nhash algorithm. It also supports an
arbitrary number of divisors and not just the one or two that Exim permits.

The nash algorithm is a fast and simple hashing algorithm that attempts to
evenly-distribute values but does not attempt to avoid collisions. Thus, it
should not be used in place of a cryptographically-secure algorithm such as
Digest::SHA. It is mainly intended for hashing filenames into directories to
avoid placing too many files into a single directory.

If nhash is not given any divisors, then the hash result is returned as-is.
If one divisor is given, the hash result is given modulo that divisor. If
more than one divisor is given, the hash result is successively divided and
the modulo at each stage returned.

Since the result is typically a 20-30 bit number, the product of all the
divisors shouldn't be more than about 2**20 or the returned values will not



( run in 0.515 second using v1.01-cache-2.11-cpan-39bf76dae61 )