1 package File
::Rsync
::Mirror
::Recentfile
::Done
;
6 use File
::Rsync
::Mirror
::Recentfile
::FakeBigFloat
qw(:all);
12 File::Rsync::Mirror::Recentfile::Done - intervals of already rsynced timespans
20 use version
; our $VERSION = qv
('0.0.1');
24 my $done = File::Rsync::Mirror::Recentfile::Done->new;
25 $done->register ( $recent_events, [3,4,5,9] ); # registers elements 3-5 and 9
26 my $boolean = $done->covered ( $epoch );
34 =head2 my $obj = CLASS->new(%hash)
36 Constructor. On every argument pair the key is a method name and the
37 value is an argument to that method name.
42 my($class, @args) = @_;
43 my $self = bless {}, $class;
45 my($method,$arg) = splice @args, 0, 2;
63 split /\n/, <<'=cut'; push @accessors, grep {s/^=item\s+//} @pod_lines; }
69 Boolean to turn on a bit verbosity.
75 use accessors
@accessors;
79 =head2 $boolean = $obj->covered ( $epoch1, $epoch2 )
81 =head2 $boolean = $obj->covered ( $epoch )
83 The first form returns true if both timestamps $epoch1 and $epoch2 in
84 floating point notation have been registered, otherwise false.
86 The second form returns true if this timestamp has been registered.
91 my($self, $epoch_high, $epoch_low) = @_;
92 my $intervals = $self->_intervals;
93 return unless @
$intervals;
94 if (defined $epoch_low) {
95 ($epoch_high,$epoch_low) = ($epoch_low,$epoch_high) if $epoch_low > $epoch_high;
97 for my $iv (@
$intervals) {
98 my($upper,$lower) = @
$iv; # may be the same
99 if (defined $epoch_low) {
101 for my $e ($epoch_high,$epoch_low) {
103 $e eq $upper || $e eq $lower || ($e < $upper && $e > $lower);
105 return 1 if $goodbound > 1;
107 return 1 if $epoch_high eq $upper || $epoch_high eq $lower || ($epoch_high < $upper && $epoch_high > $lower);
113 =head2 (void) $obj1->merge ( $obj2 )
115 Integrates all intervals in $obj2 into $obj1. Overlapping intervals
116 are conflated/folded/consolidated. Sort order is preserved as decreasing.
120 my($self, $other) = @_;
121 my $intervals = $self->_intervals;
122 my $ointervals = $other->_intervals;
123 OTHER
: for my $oiv (@
$ointervals) {
126 SELF
: for my $i (0..$#$intervals) {
127 my $iv = $intervals->[$i];
128 if ( _bigfloatlt
($oiv->[0],$iv->[1]) ) {
129 # both oiv lower than iv => next
132 if ( _bigfloatgt
($oiv->[1],$iv->[0]) ) {
133 # both oiv greater than iv => insert
137 # larger(left-iv,left-oiv) becomes left, smaller(right-iv,right-oiv) becomes right
138 $iv->[0] = _bigfloatmax
($oiv->[0],$iv->[0]);
139 $iv->[1] = _bigfloatmin
($oiv->[1],$iv->[1]);
142 unless (defined $splicepos) {
143 if ( _bigfloatlt
($oiv->[0], $intervals->[-1][1]) ) {
144 $splicepos = @
$intervals;
146 die "Panic: left-oiv[$oiv->[0]] should be smaller than smallest[$intervals->[-1][1]]";
149 splice @
$intervals, $splicepos, 0, [@
$oiv];
151 $intervals->[0] = [@
$oiv];
156 =head2 (void) $obj->register ( $recent_events_arrayref, $register_arrayref )
158 =head2 (void) $obj->register ( $recent_events_arrayref )
160 The first arrayref is a list fo hashes that contain a key called
161 C<epoch> which is a string looking like a number. The second arrayref
162 is a list if integers which point to elements in the first arrayref to
165 The second form registers all events in $recent_events_arrayref.
170 my($self, $re, $reg) = @_;
171 my $intervals = $self->_intervals;
175 REGISTRANT
: for my $i (@
$reg) {
180 intervals
=> $intervals,
186 my($self, $one) = @_;
187 my($i,$re,$intervals) = @
{$one}{qw(i re intervals)};
188 die sprintf "Panic: illegal i[%d] larger than number of events[%d]", $i, $#$re
190 my $epoch = $re->[$i]{epoch
};
191 return if $self->covered ( $epoch );
194 for my $iv (@
$intervals) {
195 my($upper,$lower) = @
$iv; # may be the same
197 && $re->[$i-1]{epoch
} eq $lower) {
202 && $re->[$i+1]{epoch
} eq $upper) {
207 if ($registered == 2) {
208 $self->_register_one_fold2
213 } elsif ($registered == 1) {
215 $self->_register_one_fold0
222 $intervals->[0] = [($epoch)x2
];
226 sub _register_one_fold0
{
232 for my $i (0..$#$intervals) {
233 if (_bigfloatgt
($epoch, $intervals->[$i][0])) {
238 unless (defined $splicepos) {
239 if (_bigfloatlt
($epoch, $intervals->[-1][1])) {
240 $splicepos = @
$intervals;
242 die "Panic: epoch[$epoch] should be smaller than smallest[$intervals->[-1][1]]";
245 splice @
$intervals, $splicepos, 0, [($epoch)x2
];
248 sub _register_one_fold2
{
254 for my $i (0..$#$intervals) {
255 if ( $epoch eq $intervals->[$i][1]
256 && $intervals->[$i][1] eq $intervals->[$i+1][0]) {
257 $intervals->[$i+1][0] = $intervals->[$i][0];
262 if (defined $splicepos) {
263 splice @
$intervals, $splicepos, 1;
265 die "Panic: Could not find an interval position to insert '$epoch'";
269 =head1 PRIVATE METHODS
276 my $x = $self->__intervals;
277 unless (defined $x) {
279 $self->__intervals ($x);
284 =head1 COPYRIGHT & LICENSE
286 Copyright 2008 Andreas König.
288 This program is free software; you can redistribute it and/or modify it
289 under the same terms as Perl itself.
293 1; # End of File::Rsync::Mirror::Recentfile
297 # cperl-indent-level: 4