line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Array::IntSpan; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2021-07-25'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Tie-Array-IntSpan'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
73176
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
10
|
1
|
|
|
1
|
|
1762
|
use Log::ger; |
|
1
|
|
|
|
|
51
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub TIEARRAY { |
13
|
1
|
|
|
1
|
|
140
|
my ($class, $intspan) = @_; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
6
|
log_trace "TIEARRAY(%s, %s)", $class, \@_; |
16
|
1
|
|
|
|
|
6
|
bless [$intspan], $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub FETCH { |
20
|
50
|
|
|
50
|
|
77
|
my ($this, $index) = @_; |
21
|
50
|
|
|
|
|
98
|
my $res = $this->[0]->lookup($index); |
22
|
50
|
|
|
|
|
947
|
log_trace "FETCH(%i) = %s", $index, $res; |
23
|
50
|
|
|
|
|
189
|
$res; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub STORE { |
27
|
2
|
|
|
2
|
|
2831
|
my ($this, $index, $value) = @_; |
28
|
2
|
|
|
|
|
7
|
log_trace "STORE(%i, %s)", $index, $value; |
29
|
2
|
|
|
|
|
10
|
$this->[0]->set($index, $value); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub FETCHSIZE { |
33
|
8
|
|
|
8
|
|
1248
|
my ($this) = @_; |
34
|
8
|
|
|
|
|
27
|
my @ranges = $this->[0]->get_range_list; |
35
|
8
|
50
|
|
|
|
115
|
my $res = !@ranges ? 0 : ($ranges[-1][1] < 0 ? die("FETCHSIZE(): Cannot handle negative range") : $ranges[-1][1]+1); |
|
|
100
|
|
|
|
|
|
36
|
8
|
|
|
|
|
22
|
log_trace "FETCHSIZE(): %s", $res; |
37
|
8
|
|
|
|
|
49
|
$res; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub STORESIZE { |
41
|
0
|
|
|
0
|
|
0
|
my ($this, $count) = @_; |
42
|
0
|
|
|
|
|
0
|
die "STORESIZE() not implemented"; |
43
|
|
|
|
|
|
|
#log_trace "STORESIZE(%i)", $count; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub EXTEND { |
47
|
0
|
|
|
0
|
|
0
|
my ($this, $count) = @_; |
48
|
0
|
|
|
|
|
0
|
die "STORESIZE() not implemented"; |
49
|
|
|
|
|
|
|
#log_trace "EXTEND(%i)", $count; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub EXISTS { |
53
|
2
|
|
|
2
|
|
2518
|
my ($this, $key) = @_; # key = index in our case |
54
|
2
|
|
|
|
|
9
|
my @ranges = $this->[0]->get_range_list; |
55
|
2
|
|
|
|
|
31
|
my $res = ""; |
56
|
2
|
100
|
66
|
|
|
5
|
for (@ranges) { if ($key >= $_->[0] && $key <= $_->[1]) { $res=1; last } } |
|
5
|
|
|
|
|
19
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
57
|
2
|
|
|
|
|
7
|
log_trace "EXISTS(%i): %s", $key, $res; |
58
|
2
|
|
|
|
|
13
|
$res; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DELETE { |
62
|
1
|
|
|
1
|
|
2144
|
my ($this, $key) = @_; # key = index in our case |
63
|
1
|
|
|
|
|
5
|
my $res = $this->[0]->lookup($key); |
64
|
1
|
|
|
|
|
26
|
$this->[0]->set($key, undef); |
65
|
1
|
|
|
|
|
137
|
log_trace "DELETE(%i): %s", $key, $res; |
66
|
1
|
|
|
|
|
5
|
$res; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub CLEAR { |
70
|
1
|
|
|
1
|
|
2541
|
my $this = shift; |
71
|
1
|
|
|
|
|
4
|
log_trace "CLEAR()"; |
72
|
1
|
|
|
|
|
6
|
$this->[0]->clear; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub PUSH { |
76
|
1
|
|
|
1
|
|
2459
|
my $this = shift; |
77
|
1
|
|
|
|
|
5
|
log_trace "PUSH(%s)", \@_; |
78
|
1
|
|
|
|
|
5
|
for (@_) { |
79
|
2
|
|
|
|
|
33
|
$this->[0]->set($this->FETCHSIZE, $_); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub POP { |
84
|
0
|
|
|
0
|
|
|
my $this = shift; |
85
|
0
|
|
|
|
|
|
die "POP() not yet implemented"; |
86
|
|
|
|
|
|
|
#log_trace "POP(): %s", $res; |
87
|
|
|
|
|
|
|
#$res; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub SHIFT { |
91
|
0
|
|
|
0
|
|
|
my $this = shift; |
92
|
0
|
|
|
|
|
|
die "SHIFT() not yet implemented"; |
93
|
|
|
|
|
|
|
#log_trace "SHIFT(): %s", $res; |
94
|
|
|
|
|
|
|
#$res; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub UNSHIFT { |
98
|
0
|
|
|
0
|
|
|
my $this = shift; |
99
|
0
|
|
|
|
|
|
die "UNSHIFT() not yet implemented"; |
100
|
|
|
|
|
|
|
#log_trace "UNSHIFT(%s)", \@_; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub SPLICE { |
104
|
0
|
|
|
0
|
|
|
my $this = shift; |
105
|
0
|
|
|
|
|
|
my $offset = shift; |
106
|
0
|
|
|
|
|
|
my $length = shift; |
107
|
0
|
|
|
|
|
|
die "UNSHIFT() not yet implemented"; |
108
|
|
|
|
|
|
|
#log_trace "SPLICE(%i, %i, %s): %s", $offset, $length, \@_, \@res; |
109
|
|
|
|
|
|
|
#@res; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub UNTIE { |
113
|
0
|
|
|
0
|
|
|
my ($this) = @_; |
114
|
0
|
|
|
|
|
|
log_trace "UNTIE()"; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# DESTROY |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
# ABSTRACT: Tied-array interface for Array::IntSpan |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |