line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Statistics::Basic::Median; |
3
|
|
|
|
|
|
|
|
4
|
33
|
|
|
33
|
|
149
|
use strict; |
|
33
|
|
|
|
|
37
|
|
|
33
|
|
|
|
|
1020
|
|
5
|
33
|
|
|
33
|
|
130
|
use warnings; |
|
33
|
|
|
|
|
37
|
|
|
33
|
|
|
|
|
649
|
|
6
|
33
|
|
|
33
|
|
117
|
use Carp; |
|
33
|
|
|
|
|
34
|
|
|
33
|
|
|
|
|
1611
|
|
7
|
|
|
|
|
|
|
|
8
|
33
|
|
|
33
|
|
148
|
use base 'Statistics::Basic::_OneVectorBase'; |
|
33
|
|
|
|
|
32
|
|
|
33
|
|
|
|
|
8963
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
12
|
|
|
12
|
1
|
1179
|
my $class = shift; |
12
|
|
|
|
|
|
|
|
13
|
12
|
50
|
|
|
|
36
|
warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2; |
14
|
|
|
|
|
|
|
|
15
|
12
|
|
|
|
|
43
|
my $this = bless {}, $class; |
16
|
12
|
50
|
|
|
|
17
|
my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@; |
|
12
|
|
|
|
|
145
|
|
17
|
12
|
100
|
|
|
|
40
|
my $c = $vector->_get_computer("median"); return $c if defined $c; |
|
12
|
|
|
|
|
42
|
|
18
|
|
|
|
|
|
|
|
19
|
9
|
|
|
|
|
204
|
$this->{v} = $vector; |
20
|
|
|
|
|
|
|
|
21
|
9
|
|
|
|
|
26
|
$vector->_set_computer( median => $this ); |
22
|
|
|
|
|
|
|
|
23
|
9
|
|
|
|
|
30
|
return $this; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _recalc { |
27
|
13
|
|
|
13
|
|
15
|
my $this = shift; |
28
|
13
|
|
|
|
|
18
|
my $v = $this->{v}; |
29
|
13
|
|
|
|
|
44
|
my $cardinality = $v->query_size; |
30
|
|
|
|
|
|
|
|
31
|
13
|
|
|
|
|
25
|
delete $this->{recalc_needed}; |
32
|
13
|
|
|
|
|
21
|
delete $this->{_value}; |
33
|
13
|
50
|
|
|
|
27
|
return unless $cardinality > 0; |
34
|
13
|
50
|
|
|
|
31
|
return unless $v->query_filled; # only applicable in certain circumstances |
35
|
|
|
|
|
|
|
|
36
|
13
|
|
|
|
|
32
|
my @v = (sort {$a <=> $b} ($v->query)); |
|
195
|
|
|
|
|
197
|
|
37
|
13
|
|
|
|
|
31
|
my $center = int($cardinality/2); |
38
|
|
|
|
|
|
|
|
39
|
33
|
|
|
33
|
|
167
|
{ no warnings 'uninitialized'; ## no critic |
|
33
|
|
|
|
|
47
|
|
|
33
|
|
|
|
|
3997
|
|
|
13
|
|
|
|
|
16
|
|
40
|
13
|
100
|
|
|
|
37
|
if ($cardinality%2) { |
41
|
10
|
|
|
|
|
21
|
$this->{_value} = $v[$center]; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} else { |
44
|
3
|
|
|
|
|
12
|
$this->{_value} = ($v[$center] + $v[$center-1])/2; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
13
|
50
|
|
|
|
28
|
warn "[recalc " . ref($this) . "] vector[int($cardinality/2)] = $this->{_value}\n" if $Statistics::Basic::DEBUG; |
49
|
|
|
|
|
|
|
|
50
|
13
|
|
|
|
|
32
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |