line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# usage: intersect( [ARRAY REF], [ARRAY REF], ... )
|
3
|
|
|
|
|
|
|
# return: ARRAY REF
|
4
|
|
|
|
|
|
|
sub intersect {
|
5
|
|
|
|
|
|
|
|
6
|
12
|
|
|
12
|
1
|
1494
|
check_prototype(@_, '(\@)+');
|
7
|
|
|
|
|
|
|
|
8
|
12
|
100
|
|
|
|
41
|
if(scalar(@_) < 2) {
|
9
|
4
|
|
|
|
|
11
|
return $_[0];
|
10
|
|
|
|
|
|
|
}
|
11
|
|
|
|
|
|
|
|
12
|
8
|
|
|
|
|
11
|
my $set1 = shift;
|
13
|
8
|
|
|
|
|
11
|
my $set2 = shift;
|
14
|
8
|
|
|
|
|
14
|
my @remain_set = @_;
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# if set1 or set2 is empty
|
17
|
8
|
100
|
100
|
|
|
26
|
if(is_empty($set1) or is_empty($set2)) {
|
18
|
2
|
|
|
|
|
9
|
return [];
|
19
|
|
|
|
|
|
|
}
|
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
|
|
9
|
my $hash2;
|
22
|
6
|
|
|
|
|
12
|
for (@$set2) {
|
23
|
21
|
|
|
|
|
46
|
$hash2->{$_} = 1;
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
|
|
37
|
$set1 = unique($set1);
|
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
9
|
my $intersect;
|
29
|
6
|
|
|
|
|
13
|
for (@$set1) {
|
30
|
19
|
100
|
|
|
|
49
|
push(@$intersect, $_) if($hash2->{$_});
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
6
|
50
|
|
|
|
16
|
if($intersect) {
|
34
|
6
|
|
|
|
|
35
|
$intersect = intersect($intersect, @remain_set);
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
else {
|
37
|
0
|
|
|
|
|
0
|
return [];
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
6
|
|
|
|
|
28
|
return $intersect;
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# usage: union( [ARRAY REF], [ARRAY REF] )
|
44
|
|
|
|
|
|
|
# return: ARRAY REF
|
45
|
|
|
|
|
|
|
sub union {
|
46
|
|
|
|
|
|
|
|
47
|
18
|
|
|
18
|
1
|
76
|
check_prototype(@_, '(\@)+');
|
48
|
|
|
|
|
|
|
|
49
|
18
|
100
|
|
|
|
58
|
if(scalar(@_) < 2) {
|
50
|
8
|
|
|
|
|
17
|
return $_[0];
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
|
53
|
10
|
|
|
|
|
16
|
my $set1 = shift;
|
54
|
10
|
|
|
|
|
15
|
my $set2 = shift;
|
55
|
10
|
|
|
|
|
18
|
my @remain_set = @_;
|
56
|
|
|
|
|
|
|
|
57
|
10
|
|
|
|
|
33
|
$set1 = unique($set1);
|
58
|
10
|
|
|
|
|
31
|
$set2 = unique($set2);
|
59
|
|
|
|
|
|
|
|
60
|
10
|
|
|
|
|
15
|
my $hash1;
|
61
|
10
|
|
|
|
|
14
|
my $union = $set1;
|
62
|
10
|
|
|
|
|
24
|
for (@$set1) {
|
63
|
35
|
|
|
|
|
71
|
$hash1->{$_} = 1;
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
10
|
|
|
|
|
20
|
for (@$set2) {
|
67
|
29
|
100
|
|
|
|
94
|
push(@$union, $_) if(! $hash1->{$_});
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
|
70
|
10
|
|
|
|
|
39
|
$union = union($union, @remain_set);
|
71
|
|
|
|
|
|
|
|
72
|
10
|
|
|
|
|
45
|
return $union;
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# usage: complement( [ARRAY REF], [ARRAY REF] )
|
76
|
|
|
|
|
|
|
# return: ARRAY REF
|
77
|
|
|
|
|
|
|
# set1 - set2
|
78
|
|
|
|
|
|
|
sub setdiff {
|
79
|
|
|
|
|
|
|
|
80
|
6
|
|
|
6
|
1
|
41
|
check_prototype(@_, '\@\@');
|
81
|
|
|
|
|
|
|
|
82
|
6
|
|
|
|
|
13
|
my $set1 = shift;
|
83
|
6
|
|
|
|
|
11
|
my $set2 = shift;
|
84
|
|
|
|
|
|
|
|
85
|
6
|
|
|
|
|
11
|
my $hash2;
|
86
|
6
|
|
|
|
|
15
|
foreach (@$set2) {
|
87
|
19
|
|
|
|
|
52
|
$hash2->{$_} = 1;
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
11
|
my $diff;
|
91
|
6
|
|
|
|
|
17
|
foreach (@$set1) {
|
92
|
45
|
100
|
|
|
|
162
|
push(@$diff, $_) unless($hash2->{$_});
|
93
|
|
|
|
|
|
|
}
|
94
|
6
|
|
|
|
|
34
|
return $diff;
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# usage: setequal( [ARRAY REF], [ARRAY REF] )
|
98
|
|
|
|
|
|
|
# return: 1|0
|
99
|
|
|
|
|
|
|
sub setequal {
|
100
|
|
|
|
|
|
|
|
101
|
4
|
|
|
4
|
1
|
1519
|
check_prototype(@_, '\@\@');
|
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
6
|
my $set1 = shift;
|
104
|
4
|
|
|
|
|
7
|
my $set2 = shift;
|
105
|
|
|
|
|
|
|
|
106
|
4
|
|
|
|
|
18
|
my $unique_set1 = unique($set1);
|
107
|
4
|
|
|
|
|
14
|
my $unique_set2 = unique($set2);
|
108
|
4
|
|
|
|
|
16
|
my $union = union($set1, $set2);
|
109
|
|
|
|
|
|
|
|
110
|
4
|
100
|
100
|
|
|
18
|
if(len($unique_set1) == len($unique_set2)
|
111
|
|
|
|
|
|
|
and len($unique_set1) == len($union)) {
|
112
|
2
|
|
|
|
|
11
|
return 1;
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
else {
|
115
|
2
|
|
|
|
|
9
|
return 0;
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# usage: is_element( [SCALAR], [ARRAY REF])
|
120
|
|
|
|
|
|
|
# return 0|1
|
121
|
|
|
|
|
|
|
sub is_element {
|
122
|
|
|
|
|
|
|
|
123
|
7
|
|
|
7
|
1
|
38
|
check_prototype(@_, '$\@');
|
124
|
|
|
|
|
|
|
|
125
|
7
|
|
|
|
|
14
|
my $item = shift;
|
126
|
7
|
|
|
|
|
10
|
my $set = shift;
|
127
|
|
|
|
|
|
|
|
128
|
7
|
|
|
|
|
33
|
for(my $i = 0; $i < len($set); $i ++) {
|
129
|
13
|
100
|
66
|
|
|
43
|
if(is_numberic($set->[$i]) and is_numberic($item)
|
|
|
100
|
100
|
|
|
|
|
130
|
|
|
|
|
|
|
and abs($set->[$i] - $item) < EPS) {
|
131
|
3
|
|
|
|
|
15
|
return 1;
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
elsif($set->[$i] eq $item) {
|
134
|
2
|
|
|
|
|
15
|
return 1;
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
}
|
137
|
2
|
|
|
|
|
10
|
return 0;
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1;
|