line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::ConsistentHash::Ketama; |
2
|
4
|
|
|
4
|
|
32384
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
151
|
|
3
|
4
|
|
|
4
|
|
1383
|
use Algorithm::ConsistentHash::Ketama::Bucket; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
90
|
|
4
|
4
|
|
|
4
|
|
18
|
use XSLoader; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
164
|
|
5
|
|
|
|
|
|
|
our $VERSION; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
4
|
|
|
4
|
|
7
|
$VERSION = '0.00012'; |
9
|
4
|
|
|
|
|
2491
|
XSLoader::load( __PACKAGE__, $VERSION ); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
use constant +{ |
12
|
4
|
|
|
|
|
808
|
HASHFUNC1 => 1, |
13
|
|
|
|
|
|
|
HASHFUNC2 => 2, |
14
|
4
|
|
|
4
|
|
21
|
}; |
|
4
|
|
|
|
|
6
|
|
15
|
|
|
|
|
|
|
our $DEFAULT_HASHFUNC = HASHFUNC1; # Use old behavior by default (broken). |
16
|
|
|
|
|
|
|
our %VALID_HASHFUNCS = map { ($_ => 1) } (HASHFUNC1, HASHFUNC2); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
5
|
|
|
5
|
1
|
4354
|
my ($class, %args) = @_; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
9
|
my $hf = $DEFAULT_HASHFUNC; |
22
|
5
|
|
|
|
|
6
|
my $x_hf = $args{use_hashfunc}; |
23
|
5
|
100
|
|
|
|
17
|
if (defined $x_hf) { |
24
|
1
|
50
|
|
|
|
6
|
if (exists $VALID_HASHFUNCS{$x_hf}) { |
25
|
1
|
|
|
|
|
2
|
$hf = $x_hf |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
# for all other values of $x_hf, ignore it |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
72
|
my $self = $class->xs_create($x_hf); |
31
|
5
|
|
|
|
|
16
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |