line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CTK::Digest::FNV32a; |
2
|
1
|
|
|
1
|
|
385
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=encoding utf-8 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
CTK::Digest::FNV32a - FNV32a Digest calculation for short strings |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 1.02 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use CTK::Digest::FNV32a; |
18
|
|
|
|
|
|
|
my $fnv32a = CTK::Digest::FNV32a->new(); |
19
|
|
|
|
|
|
|
my $digest = $fnv32a->digest( "123456789" ); # 0xbb86b11c |
20
|
|
|
|
|
|
|
my $hexdigest = $fnv32a->digest( "123456789" ); # bb86b11c |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This is Digest backend module that provides calculate FNV32a Digest for short strings |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 digest |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $digest = $fnv32a->digest( "123456789" ); # 0xbb86b11c |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Returns FNV32a Digest |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 hexdigest |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $hexdigest = $fnv32a->digest( "123456789" ); # bb86b11c |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Returns FNV32a Digest in hex form |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 HISTORY |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
See C file |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 TO DO |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
See C file |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 BUGS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
* none noted |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SEE ALSO |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
L, L, |
55
|
|
|
|
|
|
|
L, L |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 AUTHOR |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 COPYRIGHT |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 LICENSE |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
68
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
See C file and L |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
1
|
|
30
|
use vars qw/ $VERSION /; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
75
|
|
|
|
|
|
|
$VERSION = 1.02; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
1
|
|
4
|
use parent qw/CTK::Digest/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub digest { |
80
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
81
|
4
|
|
|
|
|
5
|
my $data = shift; |
82
|
4
|
50
|
|
|
|
9
|
$self->{data} = $data if defined $data; |
83
|
4
|
|
|
|
|
8
|
my $string = $self->{data}; |
84
|
4
|
|
|
|
|
4
|
my $hval = 0x811c9dc5; |
85
|
|
|
|
|
|
|
|
86
|
4
|
|
|
|
|
5
|
if ((1<<32) == 4294967296) { |
87
|
4
|
|
|
|
|
15
|
foreach my $c (unpack('C*', $string)) { |
88
|
46
|
|
|
|
|
36
|
$hval ^= $c; |
89
|
46
|
|
|
|
|
57
|
$hval += ((($hval << 1)) + (($hval << 4)) + (($hval << 7)) + (($hval << 8)) + (($hval << 24))); |
90
|
46
|
|
|
|
|
52
|
$hval = $hval & 0xffffffff; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} else { |
93
|
1
|
|
|
1
|
|
2282
|
use bigint; |
|
1
|
|
|
|
|
4624
|
|
|
1
|
|
|
|
|
4
|
|
94
|
|
|
|
|
|
|
foreach my $c (unpack('C*', $string)) { |
95
|
|
|
|
|
|
|
$hval ^= $c; |
96
|
|
|
|
|
|
|
$hval += ((($hval << 1)) + (($hval << 4)) + (($hval << 7)) + (($hval << 8)) + (($hval << 24))); |
97
|
|
|
|
|
|
|
$hval = $hval & 0xffffffff; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
4
|
|
|
|
|
15
|
return $hval; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
sub hexdigest { |
103
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
104
|
1
|
|
|
|
|
3
|
return sprintf("%x", $self->digest(@_)); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |