File: xxHash.pm

package info (click to toggle)
libcrypt-xxhash-perl 0.07-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 688 kB
  • sloc: ansic: 3,322; makefile: 406; perl: 16
file content (123 lines) | stat: -rw-r--r-- 3,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package Crypt::xxHash;
use strict;
use base qw(Exporter);
use Config ();
use XSLoader;

BEGIN {
    our $VERSION = '0.07';
    XSLoader::load __PACKAGE__, $VERSION;
}

our @EXPORT_OK = qw[
	xxhash32       xxhash32_hex
    xxhash64       xxhash64_hex
    xxhash3_64bits xxhash3_64bits_hex
                   xxhash3_128bits_hex
];

1;
__END__

=head1 NAME

Crypt::xxHash - xxHash implementation for Perl

=head1 SYNOPSIS

    use Crypt::xxHash qw/
            xxhash32 xxhash32_hex
            xxhash64 xxhash64_hex
            xxhash3_64bits xxhash3_64bits_hex
            xxhash3_128bits_hex /;

    my $hash = xxhash32( $data, $seed );
    my $hex  = xxhash32_hex( $data, $seed );

    my $hash_64 = xxhash64( $data, $seed );
    my $hex_64  = xxhash64_hex( $data, $seed );

    my $hash_64 = xxhash3_64bits( $data, $seed );
    my $hex_64  = xxhash3_64bits_hex( $data, $seed );

    my $hex_128 = xxhash3_128bits_hex( $data, $seed );

=head1 DESCRIPTION

xxHash is a super fast algorithm that claims to work at speeds close to RAM limits.
This package provides 32- and 64-bit hash functions.
As bonus it provides 128-bit hex method.

This package was inspired by C<Digest::xxHash>, but it includes the fresh C code and has
some optimisations. Thus all hex methods are implemented in Perl XS.
Also this module doesn't use C<Math::Int64> in favor of native 64 bit digits.

The used version of xxHash is v0.8.0

=head2 $h = xxhash32( $data, $seed )

Returns a 32 bit hash.

=head2 $h = xxhash32_hex( $data, $seed )

Returns a 32 bit hash converted into hex string.

=head2 $h = xxhash64( $data, $seed )

Returns a 64 bit hash.

=head2 $h = xxhash64_hex( $data, $seed )

Returns a 64 bit hash converted into hex string

=head2 $h = xxhash3_64bits( $data, $seed )

Returns a 64 bit hash which calculated by using xxHash3 algorithm.

=head2 $h = xxhash3_64bits_hex( $data, $seed )

Returns a 64 bit hash which calculated by using xxHash3 algorithm.
This hash is converted into hex string.

=head2 $h = xxhash3_128its_hex( $data, $seed )

Returns a 128 bit hash which calculated by using xxHash3 algorithm.
This hash is converted into hex string.

=head1 SPEED

There are some official benchmark results can be found on the project
web-site L<https://github.com/Cyan4973/xxHash>

=head1 BENCHMARKS

Below you can find some benchmarks in comparison with C<Digest::xxHash>.

The "xxhash32" methods in those two packages have the same realisation.
so they have the same throughput capacity.

But other methods have some differences:

                                  Rate Digest::xxHash::xxhash32_hex Crypt::xxHash::xxhash32_hex
Digest::xxHash::xxhash32_hex 2577320/s                           --                        -54%
Crypt::xxHash::xxhash32_hex  5543237/s                         115%                          --

                               Rate Digest::xxHash::xxhash64 Crypt::xxHash::xxhash64
Digest::xxHash::xxhash64   201729/s                       --                    -99%
Crypt::xxHash::xxhash64  14893617/s                    7283%                      --

                                  Rate Digest::xxHash::xxhash64_hex Crypt::xxHash::xxhash64_hex
Digest::xxHash::xxhash64_hex  185048/s                           --                        -96%
Crypt::xxHash::xxhash64_hex  4926108/s                        2562%                          --

=head1 LICENSE

xxHash is covered by the BSD license.

=head1 AUTHOR

Chernenko Dmitiry cdn@cpan.org

xxHash by Yann Collet.

=cut