line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
#made by: KorG |
3
|
|
|
|
|
|
|
# vim: sw=4 ts=4 et cc=79 : |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Data::RingBuffer::Time; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
267641
|
use 5.008; |
|
4
|
|
|
|
|
43
|
|
8
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
97
|
|
9
|
4
|
|
|
4
|
|
20
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
143
|
|
10
|
4
|
|
|
4
|
|
23
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
281
|
|
11
|
4
|
|
|
4
|
|
1853
|
use Data::RingBuffer; |
|
4
|
|
|
|
|
2267
|
|
|
4
|
|
|
|
|
248
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
$VERSION =~ tr/_//d; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
1430
|
BEGIN { our @ISA = 'Data::RingBuffer' }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Add an element to the buffer |
19
|
|
|
|
|
|
|
# args: $obj |
20
|
|
|
|
|
|
|
sub push { |
21
|
70
|
|
|
70
|
1
|
585
|
$_[0]->[0]->push(time); |
22
|
70
|
|
|
|
|
793
|
$_[0]->[1]->push($_[1]); |
23
|
70
|
|
|
|
|
705
|
return $_[1]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# (internal) find index of first element with time |
27
|
|
|
|
|
|
|
sub _find_index { |
28
|
7
|
|
|
7
|
|
13
|
my $idx = 0; |
29
|
7
|
|
|
|
|
13
|
my $buf = $_[0]->[0]->{buf}; |
30
|
7
|
|
|
|
|
32
|
while ($idx <= $#$buf) { |
31
|
30
|
100
|
|
|
|
57
|
return $idx if $buf->[$idx] > $_[1]; |
32
|
25
|
|
|
|
|
44
|
$idx++; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
5
|
return undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Get all elements in the buffer |
39
|
|
|
|
|
|
|
# args: (optional) time |
40
|
|
|
|
|
|
|
sub getall { |
41
|
11
|
100
|
|
11
|
1
|
793
|
if (defined $_[1]) { |
42
|
9
|
100
|
|
|
|
156
|
croak "Time must be positive" unless $_[1] >= 0; |
43
|
7
|
|
|
|
|
16
|
my $idx = $_[0]->_find_index($_[1]); |
44
|
7
|
100
|
|
|
|
22
|
return [] unless defined $idx; |
45
|
5
|
|
|
|
|
9
|
my $buf = $_[0]->[1]->{buf}; |
46
|
5
|
|
|
|
|
12
|
return [@{$buf}[$idx .. $#$buf]]; |
|
5
|
|
|
|
|
24
|
|
47
|
|
|
|
|
|
|
} |
48
|
2
|
|
|
|
|
11
|
return $_[0]->[1]->getall(); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Get next element from the buffer |
52
|
|
|
|
|
|
|
sub get { |
53
|
20
|
|
|
20
|
1
|
4750
|
$_[0]->[0]->get(); # handle tail movement |
54
|
20
|
|
|
|
|
133
|
$_[0]->[1]->get(); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# OO ctor |
58
|
|
|
|
|
|
|
# args: $size |
59
|
|
|
|
|
|
|
sub new { |
60
|
8
|
|
|
8
|
1
|
5076
|
bless [ |
61
|
|
|
|
|
|
|
Data::RingBuffer->new($_[1]), # time storage |
62
|
|
|
|
|
|
|
Data::RingBuffer->new($_[1]), # obj storage |
63
|
|
|
|
|
|
|
], $_[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; # End of Data::RingBuffer::Time |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |