line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Set::Light; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: (memory efficient) unordered set of strings |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require 5.006; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
251704
|
use strict; |
|
2
|
|
|
|
|
43
|
|
|
2
|
|
|
|
|
91
|
|
8
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
69
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
955
|
use Array::RefElem (); |
|
2
|
|
|
|
|
1075
|
|
|
2
|
|
|
|
|
146
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.95'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# shared undef variable |
16
|
|
|
|
|
|
|
my $UNDEF = undef; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
19
|
|
|
|
|
|
|
# handy aliases |
20
|
2
|
|
|
2
|
|
10
|
*has = \&exists; |
21
|
2
|
|
|
|
|
5
|
*contains = \&exists; |
22
|
2
|
|
|
|
|
4
|
*is_null = \&is_empty; |
23
|
2
|
|
|
|
|
638
|
*remove = \&delete; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
3
|
|
|
3
|
1
|
1034
|
my $class = shift; |
29
|
3
|
|
|
|
|
7
|
my $x = bless {}, $class; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
6
|
my $opt; |
32
|
3
|
50
|
|
|
|
11
|
$opt = shift if ref( $_[0] ) eq 'HASH'; |
33
|
|
|
|
|
|
|
|
34
|
3
|
100
|
|
|
|
13
|
$x->insert(@_) if @_ != 0; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
16
|
$x; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub insert { |
41
|
12
|
|
|
12
|
1
|
4199
|
my $x = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Note: this trick may no longer be necessesary for modern perls, |
44
|
|
|
|
|
|
|
# when storing an undef value. |
45
|
|
|
|
|
|
|
|
46
|
12
|
|
|
|
|
22
|
my $inserted = 0; |
47
|
12
|
|
|
|
|
25
|
for (@_) { |
48
|
|
|
|
|
|
|
$inserted++, Array::RefElem::hv_store( %$x, $_, $UNDEF ) |
49
|
72
|
100
|
|
|
|
198
|
unless CORE::exists $x->{$_}; |
50
|
|
|
|
|
|
|
} |
51
|
12
|
|
|
|
|
43
|
$inserted; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub is_empty { |
56
|
16
|
|
|
16
|
1
|
2781
|
my ($x) = @_; |
57
|
|
|
|
|
|
|
|
58
|
16
|
|
|
|
|
75
|
scalar keys %$x == 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub size { |
63
|
9
|
|
|
9
|
1
|
542
|
my ($x) = @_; |
64
|
|
|
|
|
|
|
|
65
|
9
|
|
|
|
|
38
|
scalar keys %$x; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub exists { |
70
|
16
|
|
|
16
|
1
|
2354
|
my ( $x, $key ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
16
|
|
|
|
|
66
|
CORE::exists $x->{$key}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub delete { |
77
|
4
|
|
|
4
|
1
|
6
|
my $x = shift; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
7
|
my $deleted = 0; |
80
|
4
|
|
|
|
|
6
|
for (@_) { |
81
|
6
|
100
|
|
|
|
18
|
$deleted++, delete $x->{$_} if CORE::exists $x->{$_}; |
82
|
|
|
|
|
|
|
} |
83
|
4
|
|
|
|
|
14
|
$deleted; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub members { |
88
|
3
|
|
|
3
|
1
|
8
|
my ($x) = @_; |
89
|
3
|
|
|
|
|
17
|
return keys %$x; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |