line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Deduper; |
2
|
3
|
|
|
3
|
|
90069
|
use strict; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
127
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1339
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
2
|
|
|
2
|
1
|
42
|
my $class = shift; |
8
|
2
|
50
|
|
|
|
14
|
my %args = ( @_ == 1 ? %{ $_[0] } : @_ ); |
|
0
|
|
|
|
|
0
|
|
9
|
|
|
|
|
|
|
bless { |
10
|
|
|
|
|
|
|
data => \@{ $args{data} } || {}, |
11
|
10
|
|
|
10
|
|
12
|
expr => $args{expr} || sub { my ( $a, $b ) = @_; $a eq $b }, |
|
10
|
|
|
|
|
28
|
|
12
|
2
|
|
50
|
|
|
5
|
size => $args{size} || 10, |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
13
|
|
|
|
|
|
|
}, |
14
|
|
|
|
|
|
|
__PACKAGE__; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub init { |
18
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
19
|
1
|
50
|
|
|
|
6
|
my @ret = ( @_ == 1 ? @{ $_[0] } : @_ ); |
|
0
|
|
|
|
|
0
|
|
20
|
1
|
|
|
|
|
3
|
my $count = @ret; |
21
|
1
|
|
|
|
|
2
|
my $size = $self->{size}; |
22
|
1
|
50
|
|
|
|
4
|
@ret = @ret[ ( $count - $size ) .. $count - 1 ] if $count > $size; |
23
|
1
|
|
|
|
|
2
|
@{ $self->{data} = \@ret }; |
|
1
|
|
|
|
|
6
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub dedup { |
27
|
2
|
|
|
2
|
0
|
18
|
my $self = shift; |
28
|
2
|
100
|
|
|
|
9
|
my @newer = ( @_ == 1 ? @{ $_[0] } : @_ ); |
|
1
|
|
|
|
|
3
|
|
29
|
2
|
|
|
|
|
5
|
my @data = @{ $self->{data} }; |
|
2
|
|
|
|
|
15
|
|
30
|
2
|
|
|
|
|
5
|
my @ret; |
31
|
2
|
|
|
|
|
6
|
for my $a (@newer) { |
32
|
4
|
100
|
|
|
|
266
|
next if grep { $self->{expr}( $_, $a ) } @data; |
|
13
|
|
|
|
|
43
|
|
33
|
2
|
|
|
|
|
4
|
push @data, $a; |
34
|
2
|
|
|
|
|
4
|
push @ret, $a; |
35
|
|
|
|
|
|
|
} |
36
|
2
|
|
|
|
|
13
|
my $count = @data; |
37
|
2
|
|
|
|
|
8
|
my $size = $self->{size}; |
38
|
2
|
100
|
|
|
|
12
|
@data = @data[ ( $count - $size ) .. $count - 1 ] if $count > $size; |
39
|
2
|
|
|
|
|
6
|
$self->{data} = \@data; |
40
|
2
|
|
|
|
|
20
|
@ret; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub data { |
44
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
45
|
2
|
|
|
|
|
4
|
@{ $self->{data} }; |
|
2
|
|
|
|
|
13
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |