line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Set::Hash; |
2
|
14
|
|
|
14
|
|
456046
|
use strict; |
|
14
|
|
|
|
|
37
|
|
|
14
|
|
|
|
|
805
|
|
3
|
14
|
|
|
14
|
|
14932
|
use attributes qw(reftype); |
|
14
|
|
|
|
|
35175
|
|
|
14
|
|
|
|
|
95
|
|
4
|
14
|
|
|
14
|
|
34358
|
use Want; |
|
14
|
|
|
|
|
48112
|
|
|
14
|
|
|
|
|
1103
|
|
5
|
14
|
|
|
14
|
|
271
|
use Carp; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
4601
|
|
6
|
14
|
|
|
14
|
|
17295
|
use Set::Array; |
|
14
|
|
|
|
|
287519
|
|
|
14
|
|
|
|
|
716
|
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
170
|
use subs qw(delete exists keys length print reverse shift values); |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
115
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use overload |
11
|
14
|
|
|
|
|
153
|
"==" => "is_equal", |
12
|
|
|
|
|
|
|
"!=" => "not_equal", |
13
|
|
|
|
|
|
|
"-" => "difference", |
14
|
|
|
|
|
|
|
"*" => "intersection", |
15
|
|
|
|
|
|
|
"+" => "push", |
16
|
|
|
|
|
|
|
"%" => "symmetric_difference", |
17
|
14
|
|
|
14
|
|
1417
|
"fallback" => 1; |
|
14
|
|
|
|
|
30
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
BEGIN{ |
20
|
14
|
|
|
14
|
|
2499
|
use vars qw(@ISA $VERSION); |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
1453
|
|
21
|
14
|
|
|
14
|
|
334
|
@ISA=qw(Set::Array); |
22
|
14
|
|
|
|
|
30289
|
$VERSION = '0.01'; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new{ |
26
|
36
|
|
|
36
|
1
|
10585
|
my($class,%hash) = @_; |
27
|
36
|
50
|
33
|
|
|
139
|
%hash = @$class if !%hash && ref($class); |
28
|
36
|
|
33
|
|
|
401
|
return bless \%hash, ref($class) || $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub clear{ |
32
|
2
|
|
|
2
|
1
|
11
|
my $self = CORE::shift; |
33
|
2
|
|
|
|
|
98
|
%$self = (); |
34
|
2
|
50
|
33
|
|
|
10
|
if(want("OBJECT") || !defined(wantarray)){ |
35
|
0
|
|
|
|
|
0
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
100
|
|
|
|
142
|
return () if wantarray; |
39
|
1
|
|
|
|
|
4
|
return {}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub delete{ |
43
|
9
|
|
|
9
|
|
38
|
my($self,@args) = @_; |
44
|
|
|
|
|
|
|
|
45
|
9
|
|
|
|
|
10
|
my @deleted = CORE::delete(@{$self}{@args}); |
|
9
|
|
|
|
|
293
|
|
46
|
|
|
|
|
|
|
|
47
|
9
|
100
|
100
|
|
|
29
|
if( want("OBJECT") || !defined(wantarray) ) |
48
|
|
|
|
|
|
|
{ |
49
|
6
|
|
|
|
|
256
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
3
|
50
|
|
|
|
174
|
return @deleted if wantarray; |
53
|
0
|
|
|
|
|
0
|
return \@deleted; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub difference{ |
57
|
6
|
|
|
6
|
1
|
3334
|
my($op1,$op2,$reversed) = @_; |
58
|
6
|
50
|
|
|
|
12
|
($op2,$op1) = ($op1,$op2) if $reversed; |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
10
|
my %diff; |
61
|
6
|
|
|
|
|
98
|
while(my($key,$val) = CORE::each(%$op1)) |
62
|
|
|
|
|
|
|
{ |
63
|
13
|
100
|
|
|
|
30
|
unless(CORE::exists($op2->{$key})) |
64
|
|
|
|
|
|
|
{ |
65
|
1
|
|
|
|
|
3
|
$diff{$key} = $val; |
66
|
1
|
|
|
|
|
5
|
next; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
12
|
100
|
|
|
|
68
|
$diff{$key} = $val unless $op1->{$key} == $op2->{$key}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
6
|
100
|
66
|
|
|
20
|
if(want("OBJECT") || !defined(wantarray)) |
73
|
|
|
|
|
|
|
{ |
74
|
2
|
|
|
|
|
121
|
%$op1 = %diff; |
75
|
2
|
|
|
|
|
12
|
return $op1; |
76
|
|
|
|
|
|
|
} |
77
|
4
|
100
|
|
|
|
207
|
return %diff if wantarray; |
78
|
2
|
|
|
|
|
7
|
return \%diff; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub exists{ |
82
|
4
|
|
|
4
|
|
13
|
my($self,@keys) = @_; |
83
|
4
|
|
|
|
|
7
|
CORE::foreach my $key(@keys) |
84
|
|
|
|
|
|
|
{ |
85
|
6
|
100
|
|
|
|
110
|
return 0 unless CORE::exists($self->{$key}); |
86
|
|
|
|
|
|
|
} |
87
|
2
|
|
|
|
|
10
|
return 1; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub intersection{ |
91
|
6
|
|
|
6
|
1
|
629
|
my($op1,$op2,$reversed) = @_; |
92
|
6
|
50
|
|
|
|
15
|
($op2,$op1) = ($op1,$op2) if $reversed; |
93
|
|
|
|
|
|
|
|
94
|
6
|
|
|
|
|
7
|
my %inter; |
95
|
6
|
|
|
|
|
92
|
while(my($key,$val) = CORE::each(%$op1)) |
96
|
|
|
|
|
|
|
{ |
97
|
15
|
100
|
|
|
|
36
|
next unless CORE::exists($op2->{$key}); |
98
|
12
|
100
|
|
|
|
38
|
if($op1->{$key} == $op2->{$key}) |
99
|
|
|
|
|
|
|
{ |
100
|
9
|
|
|
|
|
35
|
$inter{$key} = $val; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
6
|
100
|
66
|
|
|
19
|
if(want("OBJECT") || !defined(wantarray)) |
105
|
|
|
|
|
|
|
{ |
106
|
2
|
|
|
|
|
90
|
%$op1 = %inter; |
107
|
2
|
|
|
|
|
9
|
return $op1; |
108
|
|
|
|
|
|
|
} |
109
|
4
|
100
|
|
|
|
199
|
return %inter if wantarray; |
110
|
2
|
|
|
|
|
6
|
return \%inter; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub is_equal{ |
114
|
2
|
|
|
2
|
1
|
96
|
my($op1,$op2,$reversed) = @_; |
115
|
2
|
50
|
|
|
|
6
|
($op2,$op1) = ($op1,$op2) if $reversed; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Automatic failure if they're not the same length |
118
|
2
|
50
|
|
|
|
9
|
return 0 unless scalar(CORE::keys(%$op1)) == scalar(CORE::keys(%$op2)); |
119
|
|
|
|
|
|
|
|
120
|
2
|
|
|
|
|
9
|
while(my($key,$val) = CORE::each(%$op1)) |
121
|
|
|
|
|
|
|
{ |
122
|
4
|
100
|
|
|
|
23
|
return 0 unless $op1->{$key} == $op2->{$key}; |
123
|
|
|
|
|
|
|
} |
124
|
1
|
|
|
|
|
6
|
return 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub keys{ |
128
|
5
|
|
|
5
|
|
17
|
my $self = CORE::shift; |
129
|
5
|
|
|
|
|
101
|
my @keys = CORE::keys(%$self); |
130
|
5
|
100
|
66
|
|
|
19
|
if(want("OBJECT") || !defined(wantarray)){ |
131
|
2
|
|
|
|
|
90
|
return bless(\@keys); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
3
|
100
|
|
|
|
181
|
return @keys if wantarray; |
135
|
1
|
|
|
|
|
3
|
return \@keys; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub length{ |
139
|
23
|
|
|
23
|
|
1392
|
my $self = CORE::shift; |
140
|
23
|
|
|
|
|
37
|
my $length; |
141
|
|
|
|
|
|
|
|
142
|
23
|
100
|
|
|
|
191
|
if(reftype($self) eq "HASH"){ |
143
|
20
|
|
|
|
|
225
|
$length = scalar(CORE::keys(%$self)); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
else{ |
146
|
3
|
|
|
|
|
25
|
$length = $self->SUPER::length; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
23
|
50
|
33
|
|
|
202
|
if(want("OBJECT") || !defined(wantarray)){ |
150
|
0
|
|
|
|
|
0
|
return bless(\$length); |
151
|
|
|
|
|
|
|
} |
152
|
23
|
|
|
|
|
1197
|
return $length; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub not_equal{ |
156
|
2
|
|
|
2
|
1
|
85
|
my($op1,$op2,$reversed) = @_; |
157
|
2
|
50
|
|
|
|
7
|
($op2,$op1) = ($op1,$op2) if $reversed; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Automatically true if they're not the same length |
160
|
2
|
50
|
|
|
|
8
|
return 1 unless scalar(CORE::keys(%$op1)) == scalar(CORE::keys(%$op2)); |
161
|
|
|
|
|
|
|
|
162
|
2
|
|
|
|
|
8
|
while(my($key,$val) = CORE::each(%$op1)) |
163
|
|
|
|
|
|
|
{ |
164
|
4
|
100
|
|
|
|
21
|
return 1 unless $op1->{$key} == $op2->{$key}; |
165
|
|
|
|
|
|
|
} |
166
|
1
|
|
|
|
|
6
|
return 0; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub print{ |
170
|
0
|
|
|
0
|
|
0
|
my($self,$char) = @_; |
171
|
0
|
0
|
|
|
|
0
|
$char = "\n" if $char >= 1; |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
0
|
if(reftype($self) eq "HASH"){ CORE::print(%$self) } |
|
0
|
|
|
|
|
0
|
|
174
|
0
|
0
|
|
|
|
0
|
if(reftype($self) eq "ARRAY"){ CORE::print(@$self) } |
|
0
|
|
|
|
|
0
|
|
175
|
0
|
0
|
|
|
|
0
|
if(reftype($self) eq "SCALAR"){ CORE::print($$self) } |
|
0
|
|
|
|
|
0
|
|
176
|
0
|
0
|
|
|
|
0
|
CORE::print($char) if $char; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
0
|
return $self; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub push{ |
182
|
2
|
|
|
2
|
1
|
9
|
my($self,@args) = @_; |
183
|
|
|
|
|
|
|
|
184
|
2
|
50
|
|
|
|
7
|
if(ref($args[0]) eq "Set::Hash") |
185
|
|
|
|
|
|
|
{ |
186
|
0
|
|
|
|
|
0
|
my %merged; |
187
|
0
|
|
|
|
|
0
|
while(my($key,$val) = CORE::each(%$self)) |
188
|
|
|
|
|
|
|
{ |
189
|
0
|
|
|
|
|
0
|
$merged{$key} = $val; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
0
|
while(my($key,$val) = CORE::each(%{$args[0]})) |
|
0
|
|
|
|
|
0
|
|
193
|
|
|
|
|
|
|
{ |
194
|
0
|
|
|
|
|
0
|
$merged{$key} = $val; |
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
0
|
return bless \%merged; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
|
|
6
|
while(@args) |
200
|
|
|
|
|
|
|
{ |
201
|
2
|
|
|
|
|
3
|
my $key = CORE::shift(@args); |
202
|
2
|
|
100
|
|
|
10
|
my $val = CORE::shift(@args) || undef; |
203
|
2
|
|
|
|
|
99
|
$self->{$key} = $val; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
2
|
|
|
|
|
7
|
return $self; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
*unshift = \&push; |
209
|
|
|
|
|
|
|
*union = \&push; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub reverse{ |
212
|
5
|
|
|
5
|
|
460
|
my($self) = @_; |
213
|
|
|
|
|
|
|
|
214
|
5
|
100
|
66
|
|
|
17
|
if( (want('OBJECT')) || (!defined wantarray) ){ |
215
|
1
|
|
|
|
|
58
|
%$self = CORE::reverse %$self; |
216
|
1
|
|
|
|
|
4
|
return $self; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
4
|
|
|
|
|
332
|
my %temp = CORE::reverse %$self; |
220
|
4
|
100
|
|
|
|
11
|
if(wantarray){ return %temp } |
|
2
|
|
|
|
|
13
|
|
221
|
2
|
50
|
|
|
|
8
|
if(defined wantarray){ return \%temp } |
|
2
|
|
|
|
|
8
|
|
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub shift{ |
225
|
1
|
|
|
1
|
|
549
|
my $self = CORE::shift; |
226
|
|
|
|
|
|
|
|
227
|
1
|
|
|
|
|
3
|
my($key,$val) = CORE::each(%$self); |
228
|
1
|
|
|
|
|
3
|
CORE::delete($self->{$key}); |
229
|
|
|
|
|
|
|
|
230
|
1
|
50
|
|
|
|
7
|
return ($key,$val) if wantarray; |
231
|
0
|
0
|
|
|
|
0
|
return {$key,$val} if defined wantarray; |
232
|
0
|
|
|
|
|
0
|
return $self; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
*pop = \&shift; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub symmetric_difference{ |
237
|
0
|
|
|
0
|
0
|
0
|
my($op1,$op2,$reversed) = @_; |
238
|
0
|
0
|
|
|
|
0
|
($op2,$op1) = ($op1,$op2) if $reversed; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub values{ |
244
|
4
|
|
|
4
|
|
15
|
my $self = CORE::shift; |
245
|
4
|
|
|
|
|
109
|
my @vals = CORE::values(%$self); |
246
|
4
|
100
|
66
|
|
|
17
|
if(want("OBJECT") || !defined(wantarray)){ |
247
|
1
|
|
|
|
|
57
|
return bless(\@vals); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
3
|
100
|
|
|
|
193
|
return @vals if wantarray; |
251
|
1
|
|
|
|
|
4
|
return \@vals; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
1; |
254
|
|
|
|
|
|
|
__END__ |