| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Array::Set::Naive; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
4
|
|
|
|
|
|
|
our $DATE = '2021-05-15'; # DATE |
|
5
|
|
|
|
|
|
|
our $DIST = 'Array-Set-Naive'; # DIST |
|
6
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
70257
|
use strict; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
31
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# not yet used, problem with hang during build |
|
12
|
|
|
|
|
|
|
#use List::Keywords qw(any); |
|
13
|
1
|
|
|
1
|
|
6
|
use List::Util qw(any); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
110
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use Exporter qw(import); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
608
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw(set_diff set_symdiff set_union set_intersect); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub set_diff { |
|
19
|
3
|
50
|
|
3
|
1
|
1206
|
my $opts = ref($_[0]) eq 'HASH' ? shift : {}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
3
|
50
|
|
|
|
8
|
my $set1 = @_ ? shift : []; |
|
22
|
3
|
|
|
|
|
6
|
my $res = $set1; |
|
23
|
3
|
|
|
|
|
8
|
while (@_) { |
|
24
|
3
|
|
|
|
|
5
|
my $set2 = shift; |
|
25
|
3
|
|
|
|
|
5
|
$res = []; |
|
26
|
3
|
|
|
|
|
7
|
for my $el (@$set1) { |
|
27
|
10
|
100
|
|
25
|
|
30
|
push @$res, $el unless any { $_ eq $el } @$set2; |
|
|
25
|
|
|
|
|
49
|
|
|
28
|
10
|
|
|
|
|
32
|
$set1 = $res; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
3
|
|
|
|
|
14
|
$res; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub set_symdiff { |
|
35
|
3
|
50
|
|
3
|
1
|
2703
|
my $opts = ref($_[0]) eq 'HASH' ? shift : {}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
6
|
my $res = []; |
|
38
|
3
|
|
|
|
|
10
|
for my $i (0..$#_) { |
|
39
|
6
|
|
|
|
|
9
|
my $set1 = $_[$i]; |
|
40
|
|
|
|
|
|
|
ELEM: |
|
41
|
6
|
|
|
|
|
10
|
for my $el1 (@$set1) { |
|
42
|
21
|
50
|
|
18
|
|
62
|
next ELEM if any { $_ eq $el1 } @$res; |
|
|
18
|
|
|
|
|
37
|
|
|
43
|
21
|
|
|
|
|
64
|
for my $j (0..$#_) { |
|
44
|
36
|
100
|
|
|
|
71
|
next if $i == $j; |
|
45
|
24
|
|
|
|
|
30
|
my $set2 = $_[$j]; |
|
46
|
24
|
100
|
|
76
|
|
60
|
next ELEM if any { $_ eq $el1 } @$set2; |
|
|
76
|
|
|
|
|
131
|
|
|
47
|
|
|
|
|
|
|
} |
|
48
|
5
|
|
|
|
|
13
|
push @$res, $el1; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
3
|
|
|
|
|
14
|
$res; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub set_union { |
|
55
|
3
|
50
|
|
3
|
1
|
2490
|
my $opts = ref($_[0]) eq 'HASH' ? shift : {}; |
|
56
|
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
6
|
my $res = []; |
|
58
|
3
|
|
|
|
|
7
|
for my $set (@_) { |
|
59
|
6
|
|
|
|
|
11
|
for my $el (@$set) { |
|
60
|
21
|
100
|
|
54
|
|
72
|
push @$res, $el unless any { $_ eq $el } @$res; |
|
|
54
|
|
|
|
|
97
|
|
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
3
|
|
|
|
|
14
|
$res; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set_intersect { |
|
67
|
3
|
50
|
|
3
|
1
|
2491
|
my $opts = ref($_[0]) eq 'HASH' ? shift : {}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
3
|
50
|
|
|
|
11
|
return [] unless @_; |
|
70
|
3
|
|
|
|
|
5
|
my $set1 = shift @_; |
|
71
|
3
|
|
|
|
|
6
|
my $res = []; |
|
72
|
|
|
|
|
|
|
EL: |
|
73
|
3
|
|
|
|
|
6
|
for my $el (@$set1) { |
|
74
|
9
|
|
|
|
|
15
|
for my $set (@_) { |
|
75
|
11
|
100
|
|
27
|
|
33
|
next EL unless any { $_ eq $el } @$set; |
|
|
27
|
|
|
|
|
57
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
6
|
|
|
|
|
13
|
push @$res, $el; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
3
|
|
|
|
|
12
|
$res; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
# ABSTRACT: Like Array::Set, but uses naive algorithms |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |