line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Hash::Rank; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3695
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
469
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my $VERSION='1.0.1'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub TIEHASH { |
8
|
2
|
|
|
2
|
|
137
|
my $class = shift; |
9
|
2
|
|
|
|
|
18
|
my $self = { |
10
|
|
|
|
|
|
|
ALGORITHM => '$DATA{$b} <=> $DATA{$a}', # rev numeric sort |
11
|
|
|
|
|
|
|
EQUALITYSUFFIX => '', |
12
|
|
|
|
|
|
|
EQUALITYPREFIX => '', |
13
|
|
|
|
|
|
|
RECALCULATE => 'onstore', |
14
|
|
|
|
|
|
|
@_, |
15
|
|
|
|
|
|
|
_RANKS => {}, # yes, these go AFTER the parameters |
16
|
|
|
|
|
|
|
DATA => {} |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
18
|
return bless $self, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _recalculate { |
23
|
8
|
|
|
8
|
|
11
|
my $self = shift; |
24
|
8
|
|
|
|
|
14
|
my $sort_function = $self->{ALGORITHM}; |
25
|
8
|
|
|
|
|
84
|
$sort_function=~s/\$DATA\{(\$[ab])\}/\$self->{DATA}->{$1}/g; |
26
|
8
|
|
|
|
|
20
|
$self->{_RANKS} = {}; |
27
|
8
|
|
|
|
|
16
|
my $i=1; |
28
|
8
|
|
|
|
|
9
|
my $prevkey; |
29
|
8
|
|
|
|
|
771
|
foreach my $key ( |
30
|
|
|
|
|
|
|
eval("sort { $sort_function } keys %{\$self->{DATA}}") |
31
|
|
|
|
|
|
|
) { |
32
|
26
|
|
|
|
|
52
|
$self->{_RANKS}->{$key}=$i++; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
5
|
no warnings; # to avoid 'use of uninitialised value' errors |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
998
|
|
35
|
|
|
|
|
|
|
# in next line |
36
|
|
|
|
|
|
|
|
37
|
26
|
100
|
|
|
|
98
|
if($self->{DATA}->{$key} eq $self->{DATA}->{$prevkey}) { |
38
|
5
|
|
|
|
|
26
|
$self->{_RANKS}->{$key} = |
39
|
|
|
|
|
|
|
$self->{_RANKS}->{$prevkey} = |
40
|
|
|
|
|
|
|
$self->{EQUALITYPREFIX}. |
41
|
|
|
|
|
|
|
$self->{_RANKS}->{$prevkey}. |
42
|
|
|
|
|
|
|
$self->{EQUALITYSUFFIX}; |
43
|
|
|
|
|
|
|
} |
44
|
26
|
|
|
|
|
82
|
$prevkey = $key; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
2
|
|
14
|
sub CLEAR { my $self=shift; $self->{DATA}={}; $self->{_RANKS}={}; } |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
14
|
|
49
|
|
|
|
|
|
|
sub STORE { |
50
|
8
|
|
|
8
|
|
14
|
my($self, $key, $value)=@_; |
51
|
8
|
|
|
|
|
18
|
$self->{DATA}->{$key}=$value; |
52
|
8
|
100
|
|
|
|
39
|
$self->_recalculate() if($self->{RECALCULATE} eq 'onstore'); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
sub FETCH { |
55
|
8
|
|
|
8
|
|
46
|
my $self=shift; |
56
|
8
|
|
|
|
|
11
|
my $key=shift; |
57
|
8
|
100
|
|
|
|
78
|
$self->_recalculate() if($self->{RECALCULATE} eq 'onfetch'); |
58
|
8
|
|
|
|
|
41
|
return $self->{_RANKS}->{$key}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub FIRSTKEY { |
61
|
2
|
|
|
2
|
|
51
|
my $self = shift; |
62
|
2
|
|
|
|
|
3
|
scalar keys %{$self->{DATA}}; |
|
2
|
|
|
|
|
6
|
|
63
|
2
|
|
|
|
|
3
|
return scalar each %{$self->{DATA}}; |
|
2
|
|
|
|
|
10
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
sub NEXTKEY { |
66
|
8
|
|
|
8
|
|
14
|
my $self = shift; |
67
|
8
|
|
|
|
|
7
|
return scalar each %{$self->{DATA}}; |
|
8
|
|
|
|
|
32
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
sub DELETE { |
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my $key = shift; |
72
|
0
|
|
|
|
|
|
delete $self->{_RANKS}->{$key}; |
73
|
0
|
|
|
|
|
|
delete $self->{DATA}->{$key}; |
74
|
0
|
0
|
|
|
|
|
$self->_recalculate() if($self->{RECALCULATE} eq 'onstore'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub EXISTS { |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $key = shift; |
79
|
0
|
|
|
|
|
|
return exists($self->{DATA}->{$key}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |