line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package #hide |
2
|
|
|
|
|
|
|
AnyEvent::Memcached::Hash; |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
69155
|
use common::sense 2;m{ |
|
6
|
|
|
|
|
124
|
|
|
6
|
|
|
|
|
81
|
|
5
|
|
|
|
|
|
|
use strict; |
6
|
|
|
|
|
|
|
use warnings; |
7
|
|
|
|
|
|
|
}x; |
8
|
6
|
|
|
6
|
|
408
|
use Carp; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
406
|
|
9
|
6
|
|
|
6
|
|
5325
|
use String::CRC32 'crc32'; |
|
6
|
|
|
|
|
18804
|
|
|
6
|
|
|
|
|
4821
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
0
|
31
|
my $self = bless {}, shift; |
13
|
2
|
|
|
|
|
7
|
my %args = @_; |
14
|
2
|
|
|
|
|
11
|
$self->{buckets} = $args{buckets}; |
15
|
2
|
|
|
|
|
25
|
$self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
0
|
0
|
0
|
sub set_buckets { shift->{buckets} = @_ == 1 ? $_[0] : \@_ } |
19
|
|
|
|
|
|
|
|
20
|
60
|
|
|
60
|
0
|
224
|
sub hash { (crc32($_[1]) >> 16) & 0x7fff; } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub peers { |
23
|
41
|
|
|
41
|
0
|
54
|
my $self = shift; |
24
|
41
|
|
|
|
|
64
|
my ($hash,$real,$peers) = @_; |
25
|
41
|
|
50
|
|
|
75
|
$peers ||= {}; |
26
|
41
|
|
|
|
|
144
|
my $peer = $self->{buckets}->peer( $hash ); |
27
|
41
|
|
50
|
|
|
58
|
push @{ $peers->{$peer} ||= [] }, $real; |
|
41
|
|
|
|
|
232
|
|
28
|
41
|
|
|
|
|
129
|
return $peers; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub hashes { |
32
|
70
|
|
|
70
|
0
|
133
|
my $self = shift; |
33
|
70
|
50
|
|
|
|
203
|
$self->{buckets} or croak "No buckets set during hashes"; |
34
|
70
|
|
|
|
|
96
|
my $keys = shift; |
35
|
70
|
|
|
|
|
78
|
my $array; |
36
|
70
|
100
|
66
|
|
|
243
|
if (ref $keys and ref $keys eq 'ARRAY') { |
37
|
18
|
|
|
|
|
26
|
$array = 1; |
38
|
|
|
|
|
|
|
} else { |
39
|
52
|
|
|
|
|
122
|
$keys = [$keys]; |
40
|
|
|
|
|
|
|
} |
41
|
70
|
|
|
|
|
90
|
my %peers; |
42
|
70
|
|
|
|
|
121
|
for my $keyx (@$keys) { |
43
|
82
|
100
|
|
|
|
227
|
my ($hash,$real) = ref $keyx ? |
44
|
|
|
|
|
|
|
(int($keyx->[0]), $keyx->[1]) : |
45
|
|
|
|
|
|
|
($self->hash($keyx), $keyx); |
46
|
82
|
|
|
|
|
224
|
$self->peers($hash,$real,\%peers); |
47
|
|
|
|
|
|
|
} |
48
|
70
|
|
|
|
|
511
|
return \%peers; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
*servers = \&hashes; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |