| 1 | # A simple set class implemented using a hash. Supports storing references. | ||||||||||||||||||||
| 2 | # Faster then Set::Scalar for this specific use case. It significantly reduces | ||||||||||||||||||||
| 3 | # the runtime. | ||||||||||||||||||||
| 4 | package Bio::RNA::BarMap::Mapping::Set; | ||||||||||||||||||||
| 5 | 5 | our $VERSION = '0.04'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 5 | ▶ | use v5.12; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 5 | ▶ | use autodie qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 5 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 5 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 5 | ▶ | use List::Util qw(pairmap); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | # Elements are stored in a hash ref. For simple values, key is the element | ||||||||||||||||||||
| 17 | # and value is undef. For references, the key gets stringified and the | ||||||||||||||||||||
| 18 | # value stores the actual reference. | ||||||||||||||||||||
| 19 | 7088 | ▶ | has _elems => (is => "ro", init_arg => undef, default => sub { {} }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | # Return all elements. If defined, use the value, else the key. | ||||||||||||||||||||
| 22 | 0 | ▶ | sub elements { pairmap {$b // $a} %{ $_[0]->_elems } } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Subroutine
elements: not called CC=1 SCAR=6.9
Pod
documented
Condition0%0/3
$b // $a
MC/DC0%0/2
$b // $a
$b
$a
Truth table0%0/3
A // B
A= $bB= $a
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # Insert elements into the set. Returns itself. | ||||||||||||||||||||
| 25 | 6732 | ▶ | sub insert { | ||||||||||||||||||
|
Subroutine
insert: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 26 | 6732 | my $self = shift; | |||||||||||||||||||
| 27 | # Don't store simple values twice, but preserve references. | ||||||||||||||||||||
| 28 | 6732 | ▶ | $self->_elems->{$_} = ref $_ ? $_ : undef foreach @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 6732 | $self; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 5 | 1; # End of Bio::RNA::BarMap::Mapping::Set | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | __END__ | ||||||||||||||||||||