| 1 | package Algorithm::HyperLogLog; | ||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 7 | our $VERSION = '0.24'; | |||||||||
| 8 | |||||||||||
| 9 | 7 | our $PERL_ONLY; | |||||||||
| 10 | 7 | ▶ | if ( !defined $PERL_ONLY ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 5 | ▶ | $PERL_ONLY = $ENV{PERL_HLL_PUREPERL} ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | 7 | ▶ | if ( !exists $INC{'Algorithm/HyperLogLog/PP.pm'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 7 | ▶ | if ( !$PERL_ONLY ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 5 | require XSLoader; | |||||||||
| 17 | 5 | $PERL_ONLY = !eval { XSLoader::load( __PACKAGE__, $VERSION ); }; | |||||||||
| 18 | } | ||||||||||
| 19 | 7 | ▶ | if ($PERL_ONLY) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 7 | require 'Algorithm/HyperLogLog/PP.pm'; | |||||||||
| 21 | } | ||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 2 | ▶ | sub new_from_file { | ||||||||
|
Subroutine
new_from_file: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||
| 25 | 2 | my ( $class, $filename ) = @_; | |||||||||
| 26 | 2 | ▶ | open my $fh, '<', $filename or die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | my $on_error = sub { close $fh; croak "Invalid dump file($filename)"; }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 28 | |||||||||||
| 29 | 2 | binmode $fh; | |||||||||
| 30 | 2 | my ( @dumpdata, $buf, $readed ); | |||||||||
| 31 | |||||||||||
| 32 | # Read register size data | ||||||||||
| 33 | 2 | $readed = read( $fh, $buf, 1 ); | |||||||||
| 34 | 2 | ▶ | $on_error->() if $readed != 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 2 | my $k = unpack 'C', $buf; | |||||||||
| 36 | |||||||||||
| 37 | # Read register content data | ||||||||||
| 38 | 2 | my $m = 2**$k; | |||||||||
| 39 | 2 | $readed = read $fh, $buf, $m; | |||||||||
| 40 | 2 | ▶ | $on_error->() if $readed != $m; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 2 | close $fh; | |||||||||
| 42 | 2 | @dumpdata = unpack 'C*', $buf; | |||||||||
| 43 | 2 | my $self = $class->_new_from_dump( $k, \@dumpdata ); | |||||||||
| 44 | 2 | return $self; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 2 | ▶ | sub dump_to_file { | ||||||||
|
Subroutine
dump_to_file: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 2 | my ( $self, $filename ) = @_; | |||||||||
| 49 | 2 | my $k = log( $self->register_size ) / log(2); # Calculate log2(register_size) | |||||||||
| 50 | 2 | my $dumpdata = $self->_dump_register(); | |||||||||
| 51 | 2 | ▶ | open my $fh, '>', $filename or die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 2 | binmode $fh; | |||||||||
| 53 | 2 | my $buf = pack 'C', $k; | |||||||||
| 54 | 2 | print $fh $buf; | |||||||||
| 55 | 2 | $buf = pack 'C*', @$dumpdata; | |||||||||
| 56 | 2 | print $fh $buf; | |||||||||
| 57 | 2 | close $fh; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 4 | ▶ | sub XS { | ||||||||
|
Subroutine
XS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 61 | 4 | !$PERL_ONLY; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 7 | 1; | |||||||||
| 65 | __END__ | ||||||||||