line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Util::Uniq; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
67368
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
595
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
9
|
|
|
|
|
|
|
our $DATE = '2023-06-20'; # DATE |
10
|
|
|
|
|
|
|
our $DIST = 'List-Util-Uniq'; # DIST |
11
|
|
|
|
|
|
|
our $VERSION = '0.005'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
uniq |
15
|
|
|
|
|
|
|
uniqnum |
16
|
|
|
|
|
|
|
uniqstr |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
uniq_adj |
19
|
|
|
|
|
|
|
uniq_adj_ci |
20
|
|
|
|
|
|
|
uniq_ci |
21
|
|
|
|
|
|
|
is_uniq |
22
|
|
|
|
|
|
|
is_uniq_ci |
23
|
|
|
|
|
|
|
is_monovalued |
24
|
|
|
|
|
|
|
is_monovalued_ci |
25
|
|
|
|
|
|
|
dupe |
26
|
|
|
|
|
|
|
dupenum |
27
|
|
|
|
|
|
|
dupestr |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub uniq_adj { |
31
|
2
|
|
|
2
|
1
|
3967
|
my @res; |
32
|
|
|
|
|
|
|
|
33
|
2
|
50
|
|
|
|
7
|
return () unless @_; |
34
|
2
|
|
|
|
|
4
|
my $last = shift; |
35
|
2
|
|
|
|
|
4
|
push @res, $last; |
36
|
2
|
|
|
|
|
6
|
for (@_) { |
37
|
12
|
0
|
33
|
|
|
21
|
next if !defined($_) && !defined($last); |
38
|
|
|
|
|
|
|
# XXX $_ becomes stringified |
39
|
12
|
100
|
33
|
|
|
49
|
next if defined($_) && defined($last) && $_ eq $last; |
|
|
|
66
|
|
|
|
|
40
|
10
|
|
|
|
|
16
|
push @res, $_; |
41
|
10
|
|
|
|
|
15
|
$last = $_; |
42
|
|
|
|
|
|
|
} |
43
|
2
|
|
|
|
|
14
|
@res; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub uniq_adj_ci { |
47
|
1
|
|
|
1
|
1
|
3
|
my @res; |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
4
|
return () unless @_; |
50
|
1
|
|
|
|
|
2
|
my $last = shift; |
51
|
1
|
|
|
|
|
2
|
push @res, $last; |
52
|
1
|
|
|
|
|
2
|
for (@_) { |
53
|
6
|
0
|
33
|
|
|
26
|
next if !defined($_) && !defined($last); |
54
|
|
|
|
|
|
|
# XXX $_ becomes stringified |
55
|
6
|
100
|
33
|
|
|
28
|
next if defined($_) && defined($last) && lc($_) eq lc($last); |
|
|
|
66
|
|
|
|
|
56
|
4
|
|
|
|
|
6
|
push @res, $_; |
57
|
4
|
|
|
|
|
6
|
$last = $_; |
58
|
|
|
|
|
|
|
} |
59
|
1
|
|
|
|
|
7
|
@res; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub uniq_ci { |
63
|
2
|
|
|
2
|
1
|
2454
|
my @res; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my %mem; |
66
|
2
|
|
|
|
|
0
|
my $undef_added; |
67
|
2
|
|
|
|
|
6
|
for (@_) { |
68
|
13
|
100
|
|
|
|
26
|
if (defined) { |
69
|
11
|
100
|
|
|
|
28
|
push @res, $_ unless $mem{lc $_}++; |
70
|
|
|
|
|
|
|
} else { |
71
|
2
|
100
|
|
|
|
12
|
push @res, $_ unless $undef_added++; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
2
|
|
|
|
|
15
|
@res; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_uniq { |
78
|
5
|
|
|
5
|
1
|
2471
|
my %vals; |
79
|
5
|
|
|
|
|
23
|
for (@_) { |
80
|
7
|
100
|
|
|
|
25
|
return 0 if $vals{$_}++; |
81
|
|
|
|
|
|
|
} |
82
|
4
|
|
|
|
|
18
|
1; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub is_uniq_ci { |
86
|
5
|
|
|
5
|
1
|
2187
|
my %vals; |
87
|
5
|
|
|
|
|
15
|
for (@_) { |
88
|
7
|
100
|
|
|
|
28
|
return 0 if $vals{lc $_}++; |
89
|
|
|
|
|
|
|
} |
90
|
3
|
|
|
|
|
15
|
1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub is_monovalued { |
94
|
5
|
|
|
5
|
1
|
2197
|
my %vals; |
95
|
5
|
|
|
|
|
10
|
for (@_) { |
96
|
7
|
|
|
|
|
17
|
$vals{$_} = 1; |
97
|
7
|
100
|
|
|
|
25
|
return 0 if keys(%vals) > 1; |
98
|
|
|
|
|
|
|
} |
99
|
3
|
|
|
|
|
12
|
1; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub is_monovalued_ci { |
103
|
5
|
|
|
5
|
1
|
2162
|
my %vals; |
104
|
5
|
|
|
|
|
11
|
for (@_) { |
105
|
7
|
|
|
|
|
14
|
$vals{lc $_} = 1; |
106
|
7
|
100
|
|
|
|
25
|
return 0 if keys(%vals) > 1; |
107
|
|
|
|
|
|
|
} |
108
|
4
|
|
|
|
|
20
|
1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub uniqstr { |
112
|
2
|
|
|
2
|
0
|
3
|
my (@uniqs, %vals); |
113
|
2
|
|
|
|
|
4
|
for (@_) { |
114
|
7
|
100
|
|
|
|
19
|
++$vals{$_} == 1 and push @uniqs, $_; |
115
|
|
|
|
|
|
|
} |
116
|
2
|
|
|
|
|
11
|
@uniqs; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub uniqnum { |
120
|
1
|
|
|
1
|
0
|
3
|
my (@uniqs, %vals); |
121
|
1
|
|
|
|
|
8
|
for (@_) { |
122
|
1
|
|
|
1
|
|
8
|
no warnings 'numeric'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
160
|
|
123
|
4
|
100
|
|
|
|
13
|
++$vals{$_+0} == 1 and push @uniqs, $_; |
124
|
|
|
|
|
|
|
} |
125
|
1
|
|
|
|
|
4
|
@uniqs; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
1
|
0
|
3
|
sub uniq { goto \&uniqstr } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub dupestr { |
131
|
10
|
|
|
10
|
1
|
2410
|
my (@dupes, %vals); |
132
|
10
|
|
|
|
|
20
|
for (@_) { |
133
|
46
|
100
|
|
|
|
112
|
++$vals{$_} > 1 and push @dupes, $_; |
134
|
|
|
|
|
|
|
} |
135
|
10
|
|
|
|
|
58
|
@dupes; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub dupenum { |
139
|
5
|
|
|
5
|
1
|
2393
|
my (@dupes, %vals); |
140
|
5
|
|
|
|
|
12
|
for (@_) { |
141
|
1
|
|
|
1
|
|
7
|
no warnings 'numeric'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
102
|
|
142
|
18
|
100
|
|
|
|
52
|
++$vals{$_+0} > 1 and push @dupes, $_; |
143
|
|
|
|
|
|
|
} |
144
|
5
|
|
|
|
|
26
|
@dupes; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
5
|
|
|
5
|
1
|
2204
|
sub dupe { goto \&dupestr } |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
# ABSTRACT: List utilities related to finding unique items |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__ |