line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hub::Knots::SortedHash; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
58
|
|
3
|
1
|
|
|
1
|
|
6
|
use Hub qw/:lib/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
our $VERSION = '4.00043'; |
5
|
|
|
|
|
|
|
our @EXPORT = qw//; |
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw//; |
7
|
|
|
|
|
|
|
push our @ISA, qw(Tie::StdHash); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# KEYS - Private hash member which holds the sorted list of keys |
10
|
1
|
|
|
1
|
|
7
|
use constant KEYS => '.keys'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
70
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ITR - Private hash member which holds the index while iterating |
13
|
1
|
|
|
1
|
|
6
|
use constant ITR => '.iterator'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
537
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub clear_sort_keys { |
16
|
0
|
|
|
0
|
1
|
0
|
$_[0]->{KEYS} = []; |
17
|
0
|
|
|
|
|
0
|
$_[0]->{ITR} = 0; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub set_sort_keys { |
21
|
8
|
|
|
8
|
1
|
11
|
my $self = shift; |
22
|
8
|
|
|
|
|
27
|
$self->{KEYS} = [@_]; |
23
|
8
|
|
|
|
|
21
|
$self->{ITR} = 0; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
27
|
|
|
|
|
|
|
# TIEHASH - Initialize private hash members |
28
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub TIEHASH { |
31
|
16
|
|
|
16
|
|
152
|
bless {+KEYS => [], +ITR => 0}, $_[0]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
35
|
|
|
|
|
|
|
# STORE - Add the key to the sorted list |
36
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub STORE { |
39
|
|
|
|
|
|
|
#warn " +store: $_[1] = $_[2]\n"; |
40
|
59
|
|
|
59
|
|
137
|
$_[0]->{$_[1]} = $_[2]; |
41
|
59
|
|
|
|
|
65
|
my $k = $_[1]; |
42
|
59
|
50
|
|
|
|
60
|
push @{$_[0]->{KEYS}}, $_[1] unless grep { $k eq $_ } @{$_[0]->{KEYS}}; |
|
0
|
|
|
|
|
0
|
|
|
615
|
|
|
|
|
915
|
|
|
59
|
|
|
|
|
99
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub FETCH { |
46
|
|
|
|
|
|
|
#warn " +fetch: $_[1] is $_[0]->{$_[1]}\n"; |
47
|
177
|
|
|
177
|
|
1077
|
$_[0]->{$_[1]}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
51
|
|
|
|
|
|
|
# FIRSTKEY - Set iterator to zero and return the first key in the sorted list |
52
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub FIRSTKEY { |
55
|
15
|
|
|
15
|
|
38
|
$_[0]->{ITR} = 0; |
56
|
15
|
|
|
|
|
154
|
$_[0]->{KEYS}[0]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
60
|
|
|
|
|
|
|
# NEXTKEY - Increment the iterator return the key at that index |
61
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub NEXTKEY { |
64
|
59
|
|
|
59
|
|
63
|
$_[0]->{ITR}++; |
65
|
59
|
|
|
|
|
90
|
my $k = $_[0]->{KEYS}[$_[0]->{ITR}]; |
66
|
59
|
|
|
|
|
386
|
$k; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
70
|
|
|
|
|
|
|
# DELETE - Remove the key from the sorted list |
71
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub DELETE { |
74
|
0
|
|
|
0
|
|
|
delete $_[0]->{$_[1]}; |
75
|
0
|
0
|
|
|
|
|
unless($_[1] eq KEYS) { |
76
|
0
|
|
|
|
|
|
my $p = 0; |
77
|
0
|
|
|
|
|
|
my $k = $_[1]; |
78
|
0
|
|
|
|
|
|
for (@{$_[0]->{KEYS}}) { |
|
0
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
$_ eq $k and last; |
80
|
0
|
|
|
|
|
|
$p++; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
splice @{$_[0]->{KEYS}}, $p, 1; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |