| 1 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 2 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 3 | ## Ordered-hash helper class. | ||||||||||||||||||||||||||||||||
| 4 | ## | ||||||||||||||||||||||||||||||||
| 5 | ## An optimized, pure-Perl ordered hash implementation featuring tombstone | ||||||||||||||||||||||||||||||||
| 6 | ## deletion, inspired by Hash::Ordered v0.009. | ||||||||||||||||||||||||||||||||
| 7 | ## | ||||||||||||||||||||||||||||||||
| 8 | ## 1. Added splice, sorting, plus extra capabilities for use with MCE::Shared. | ||||||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||||||
| 10 | ## 2. Revised tombstone deletion to not impact store, push, unshift, and merge. | ||||||||||||||||||||||||||||||||
| 11 | ## Tombstones are purged in-place for overall lesser memory consumption. | ||||||||||||||||||||||||||||||||
| 12 | ## Also, minimized overhead in pop and shift when an index is present. | ||||||||||||||||||||||||||||||||
| 13 | ## Ditto for forward and reverse deletes. | ||||||||||||||||||||||||||||||||
| 14 | ## | ||||||||||||||||||||||||||||||||
| 15 | ## 3. Provides support for hash-like dereferencing. | ||||||||||||||||||||||||||||||||
| 16 | ## | ||||||||||||||||||||||||||||||||
| 17 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | package MCE::Shared::Ordhash; | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | no warnings qw( threads recursion uninitialized numeric ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 4 | our $VERSION = '1.894'; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | ## no critic (Subroutines::ProhibitExplicitReturnUndef) | ||||||||||||||||||||||||||||||||
| 31 | ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | use MCE::Shared::Base (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | use base 'MCE::Shared::Common'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | use constant { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 37 | 4 | _DATA => 0, # unordered data | |||||||||||||||||||||||||||||||
| 38 | _KEYS => 1, # ordered keys | ||||||||||||||||||||||||||||||||
| 39 | _INDX => 2, # index into _KEYS (on demand, no impact to STORE) | ||||||||||||||||||||||||||||||||
| 40 | _BEGI => 3, # begin ordered id for optimized shift/unshift | ||||||||||||||||||||||||||||||||
| 41 | _GCNT => 4, # garbage count | ||||||||||||||||||||||||||||||||
| 42 | _HREF => 5, # for hash-like dereferencing | ||||||||||||||||||||||||||||||||
| 43 | _ITER => 6, # for tied hash support | ||||||||||||||||||||||||||||||||
| 44 | 4 | }; | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | use overload ( | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 47 | q("") => \&MCE::Shared::Base::_stringify, | ||||||||||||||||||||||||||||||||
| 48 | q(0+) => \&MCE::Shared::Base::_numify, | ||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | q(%{}) => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | no overloading; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $_[0]->[_HREF] || do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | # no circular reference to original, therefore no memory leaks | ||||||||||||||||||||||||||||||||
| 53 | 0 | tie my %h, __PACKAGE__.'::_href', bless([ @{ $_[0] } ], __PACKAGE__); | |||||||||||||||||||||||||||||||
| 54 | 0 | $_[0]->[_HREF] = \%h; | |||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||||||
| 57 | 4 | fallback => 1 | |||||||||||||||||||||||||||||||
| 58 | 4 | ); | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 61 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 62 | ## TIEHASH, STORE, FETCH, DELETE, FIRSTKEY, NEXTKEY, EXISTS, CLEAR, SCALAR | ||||||||||||||||||||||||||||||||
| 63 | ## | ||||||||||||||||||||||||||||||||
| 64 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | # TIEHASH ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||
| 67 | # TIEHASH ( ) | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub TIEHASH { | ||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=3 SCAR=13.5
| |||||||||||||||||||||||||||||||||
| 70 | 1 | my ( $class ) = ( shift ); | |||||||||||||||||||||||||||||||
| 71 | 1 | my ( $begi, $gcnt ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||
| 72 | 1 | my ( $key, %data, @keys ); | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | push @keys, "$key" unless ( exists $data{ $key = shift } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | 0 | $data{ $key } = shift; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 1 | bless [ \%data, \@keys, {}, \$begi, \$gcnt ], $class; | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | # STORE ( key, value ) | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 20 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 85 | 20 | my ( $self, $key ) = @_; # do not copy $_[2] in case it's large | |||||||||||||||||||||||||||||||
| 86 | 20 | ▶ | push @{ $self->[_KEYS] }, "$key" unless ( exists $self->[_DATA]{$key} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 20 | $self->[_DATA]{$key} = $_[2]; | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | # FETCH ( key ) | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 94 | 0 | $_[0]->[_DATA]{ $_[1] }; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | # DELETE ( key ) | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 4 | ▶ | sub DELETE { | ||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=19 SCAR=49.7
| |||||||||||||||||||||||||||||||||
| 100 | 4 | my ( $key, $data, $keys, $indx, $begi, $gcnt ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | # check the first key | ||||||||||||||||||||||||||||||||
| 103 | 4 | ▶ | if ( $key eq $keys->[0] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 104 | 0 | shift @{ $keys }; | |||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | ${ $begi }++, delete $indx->{ $key } if %{ $indx }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( ! @{ $keys } ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 108 | 0 | ${ $begi } = 0; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | elsif ( !defined $keys->[0] ) { | ||||||||||||||||||||||||||||||||
| 111 | # GC start of list | ||||||||||||||||||||||||||||||||
| 112 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $i++ until ( defined $keys->[$i] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | 0 | ${ $begi } += $i, ${ $gcnt } -= $i; | |||||||||||||||||||||||||||||||
| 115 | 0 | splice @{ $keys }, 0, $i; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | return delete $data->{ $key }; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | # check the last key | ||||||||||||||||||||||||||||||||
| 122 | elsif ( $key eq $keys->[-1] ) { | ||||||||||||||||||||||||||||||||
| 123 | 0 | pop @{ $keys }; | |||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | delete $indx->{ $key } if %{ $indx }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ( ! @{ $keys } ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 127 | 0 | ${ $begi } = 0; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | elsif ( !defined $keys->[-1] ) { | ||||||||||||||||||||||||||||||||
| 130 | # GC end of list | ||||||||||||||||||||||||||||||||
| 131 | 0 | my $i = $#{ $keys } - 1; | |||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $i-- until ( defined $keys->[$i] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | ${ $gcnt } -= $#{ $keys } - $i; | |||||||||||||||||||||||||||||||
| 134 | 0 | splice @{ $keys }, $i + 1; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | return delete $data->{ $key }; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | # fill the index on-demand | ||||||||||||||||||||||||||||||||
| 141 | 4 | ▶ | my $off = delete $indx->{ $key } // do { | ||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $indx->{$key} // do {
return undef unless exists $data->{$key};
%{$indx;} ? $_[0]->_fill_index : do {
$_[0]->purge if ${$gcnt;};
my $i;
$i = (${$begi;} = 0);
$$indx{$keys->[$_]} = $i++ foreach (0 .. $#{$keys;})
};
delete $indx->{$key}
}
MC/DC0%0/2
delete $indx->{$key} // do {
return undef unless exists $data->{$key};
%{$indx;} ? $_[0]->_fill_index : do {
$_[0]->purge if ${$gcnt;};
my $i;
$i = (${$begi;} = 0);
$$indx{$keys->[$_]} = $i++ foreach (0 .. $#{$keys;})
};
delete $indx->{$key}
}
delete $indx->{$key}
do {
return undef unless exists $data->{$key};
%{$indx;} ? $_[0]->_fill_index : do {
$_[0]->purge if ${$gcnt;};
my $i;
$i = (${$begi;} = 0);
$$indx{$keys->[$_]} = $i++ foreach (0 .. $#{$keys;})
};
delete $indx->{$key}
}
Truth table33%1/3
A // B
A= delete $indx->{$key}B= do {
return undef unless exists $data->{$key};
%{$indx;} ? $_[0]->_fill_index : do {
$_[0]->purge if ${$gcnt;};
my $i;
$i = (${$begi;} = 0);
$$indx{$keys->[$_]} = $i++ foreach (0 .. $#{$keys;})
};
delete $indx->{$key}
}
| |||||||||||||||||||||||||||||||||
| 142 | 4 | ▶ | return undef unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 4 | ▶ | %{ $indx } ? $_[0]->_fill_index : do { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | $_[0]->purge if ${ $gcnt }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | 2 | my $i; $i = ${ $begi } = 0; | |||||||||||||||||||||||||||||||
| 147 | 2 | $indx->{ $keys->[$_] } = $i++ for 0..$#{ $keys }; | |||||||||||||||||||||||||||||||
| 148 | }; | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 4 | delete $indx->{ $key }; | |||||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 4 | $keys->[ $off - ${ $begi } ] = undef; # tombstone | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | # GC keys and refresh index | ||||||||||||||||||||||||||||||||
| 156 | 4 | ▶ | if ( ++${ $gcnt } > @{ $keys } * 0.667 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | 0 | my $i; $i = ${ $begi } = ${ $gcnt } = 0; | |||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 0 | for my $k ( @{ $keys } ) { | |||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $keys->[ $i ] = $k, $indx->{ $k } = $i++ if ( defined $k ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 0 | splice @{ $keys }, $i; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 4 | delete $data->{ $key }; | |||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | # FIRSTKEY ( ) | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub FIRSTKEY { | ||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 173 | 0 | $self->[_ITER] = [ $self->keys ]; | |||||||||||||||||||||||||||||||
| 174 | 0 | shift @{ $self->[_ITER] }; | |||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | # NEXTKEY ( ) | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub NEXTKEY { | ||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 180 | 0 | shift @{ $_[0]->[_ITER] }; | |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | # EXISTS ( key ) | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub EXISTS { | ||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 186 | 0 | exists $_[0]->[_DATA]{ $_[1] }; | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | # CLEAR ( ) | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 2 | ▶ | sub CLEAR { | ||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 192 | 2 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | 2 | %{ $data } = @{ $keys } = %{ $indx } = (); | |||||||||||||||||||||||||||||||
| 195 | 2 | ${ $begi } = ${ $gcnt } = 0; | |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 2 | delete $_[0]->[_ITER]; | |||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 2 | return; | |||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | # SCALAR ( ) | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub SCALAR { | ||||||||||||||||||||||||||||||
|
Subroutine
SCALAR: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 205 | 0 | scalar keys %{ $_[0]->[_DATA] }; | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | # _fill_index ( ) | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 2 | ▶ | sub _fill_index { | ||||||||||||||||||||||||||||||
|
Subroutine
_fill_index: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||
| 211 | 2 | my ( $data, $keys, $indx, $begi ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | # from start of list | ||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | if ( !exists $indx->{ $keys->[0] } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 215 | 2 | my $i = ${ $begi }; | |||||||||||||||||||||||||||||||
| 216 | 2 | for my $k ( @{ $keys } ) { | |||||||||||||||||||||||||||||||
| 217 | 6 | ▶ | $i++, next unless ( defined $k ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | 6 | ▶ | last if ( exists $indx->{ $k } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | 4 | $indx->{ $k } = $i++; | |||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | # from end of list | ||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | if ( !exists $indx->{ $keys->[-1] } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 225 | 2 | my $i = ${ $begi } + @{ $keys } - 1; | |||||||||||||||||||||||||||||||
| 226 | 2 | for my $k ( reverse @{ $keys } ) { | |||||||||||||||||||||||||||||||
| 227 | 6 | ▶ | $i--, next unless ( defined $k ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 228 | 6 | ▶ | last if ( exists $indx->{ $k } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | 4 | $indx->{ $k } = $i--; | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 2 | return; | |||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 237 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 238 | ## POP, PUSH, SHIFT, UNSHIFT, SPLICE | ||||||||||||||||||||||||||||||||
| 239 | ## | ||||||||||||||||||||||||||||||||
| 240 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | # POP ( ) | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub POP { | ||||||||||||||||||||||||||||||
|
Subroutine
POP: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 245 | 0 | my ( $data, $keys, $indx ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||
| 246 | 0 | my $key = pop @{ $keys }; | |||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | delete $indx->{ $key } if %{ $indx }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ( ! @{ $keys } ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 251 | 0 | ${ $_[0]->[_BEGI] } = 0; | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | elsif ( !defined $keys->[-1] ) { | ||||||||||||||||||||||||||||||||
| 254 | # GC end of list | ||||||||||||||||||||||||||||||||
| 255 | 0 | my $i = $#{ $keys } - 1; | |||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $i-- until ( defined $keys->[$i] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 257 | 0 | ${ $_[0]->[_GCNT] } -= $#{ $keys } - $i; | |||||||||||||||||||||||||||||||
| 258 | 0 | splice @{ $keys }, $i + 1; | |||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | defined $key ? ( $key, delete $data->{ $key } ) : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | # PUSH ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | 4 | ▶ | sub PUSH { | ||||||||||||||||||||||||||||||
|
Subroutine
PUSH: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||
| 267 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 268 | 4 | my ( $data, $keys ) = @{ $self }; | |||||||||||||||||||||||||||||||
| 269 | 4 | my $key; | |||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 4 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 272 | 4 | ▶ | $self->delete( $key ) if ( exists $data->{ $key = shift } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 273 | 4 | $data->{ $key } = shift, push @{ $keys }, "$key"; | |||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | defined wantarray ? scalar keys %{ $data } : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | # SHIFT ( ) | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub SHIFT { | ||||||||||||||||||||||||||||||
|
Subroutine
SHIFT: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 282 | 0 | my ( $data, $keys, $indx ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||
| 283 | 0 | my $key = shift @{ $keys }; | |||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | ${ $_[0]->[_BEGI] }++, delete $indx->{ $key } if %{ $indx }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ( ! @{ $keys } ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 288 | 0 | ${ $_[0]->[_BEGI] } = 0; | |||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||
| 290 | elsif ( !defined $keys->[0] ) { | ||||||||||||||||||||||||||||||||
| 291 | # GC start of list | ||||||||||||||||||||||||||||||||
| 292 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $i++ until ( defined $keys->[$i] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 294 | 0 | ${ $_[0]->[_BEGI] } += $i, ${ $_[0]->[_GCNT] } -= $i; | |||||||||||||||||||||||||||||||
| 295 | 0 | splice @{ $keys }, 0, $i; | |||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | defined $key ? ( $key, delete $data->{ $key } ) : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | # UNSHIFT ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | 4 | ▶ | sub UNSHIFT { | ||||||||||||||||||||||||||||||
|
Subroutine
UNSHIFT: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||
| 304 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 305 | 4 | my ( $data, $keys, $indx, $begi ) = @{ $self }; | |||||||||||||||||||||||||||||||
| 306 | 4 | my $key; | |||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | 4 | ▶ | $self->delete( $key ) if ( exists $data->{ $key = $_[-2] } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | 4 | $data->{ $key } = pop, pop, unshift @{ $keys }, "$key"; | |||||||||||||||||||||||||||||||
| 311 | 4 | ▶ | ${ $begi }-- if %{ $indx }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | defined wantarray ? scalar keys %{ $data } : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | # SPLICE ( offset [, length [, key, value, ... ] ] ) | ||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub SPLICE { | ||||||||||||||||||||||||||||||
|
Subroutine
SPLICE: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||
| 320 | 0 | my ( $self, $off ) = ( shift, shift ); | |||||||||||||||||||||||||||||||
| 321 | 0 | my ( $data, $keys ) = @{ $self }; | |||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | return () unless ( defined $off ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $self->purge if %{ $self->[_INDX] }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | 0 | my $size = scalar @{ $keys }; | |||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | my $len = @_ ? shift : $size - $off; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | 0 | my @ret; | |||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ( $off >= $size ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | $self->push( @_ ) if @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||
| 333 | elsif ( abs($off) <= $size ) { | ||||||||||||||||||||||||||||||||
| 334 | 0 | local $_; | |||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ( $len > 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $off = $off + @{ $keys } if ( $off < 0 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 337 | 0 | my @k = splice @{ $keys }, $off, $len; | |||||||||||||||||||||||||||||||
| 338 | 0 | push(@ret, $_, delete $data->{ $_ }) for @k; | |||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 341 | 0 | my @k = splice @{ $keys }, $off; | |||||||||||||||||||||||||||||||
| 342 | 0 | $self->push( @_ ); | |||||||||||||||||||||||||||||||
| 343 | 0 | push(@{ $keys }, "$_") for @k; | |||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | 0 | return @ret; | |||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 351 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 352 | ## _find, clone, flush, iterator, keys, pairs, values | ||||||||||||||||||||||||||||||||
| 353 | ## | ||||||||||||||||||||||||||||||||
| 354 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | # _find ( { getkeys => 1 }, "query string" ) | ||||||||||||||||||||||||||||||||
| 357 | # _find ( { getvals => 1 }, "query string" ) | ||||||||||||||||||||||||||||||||
| 358 | # _find ( "query string" ) # pairs | ||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | sub _find { | ||||||||||||||||||||||||||||||
|
Subroutine
_find: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 361 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | my $params = ref($_[0]) eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 363 | 0 | my $query = shift; | |||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | 0 | MCE::Shared::Base::_find_hash( $self->[_DATA], $params, $query, $self ); | |||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||
| 368 | # clone ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 369 | # clone ( ) | ||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 372 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | my $params = ref($_[0]) eq 'HASH' ? shift : {}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 374 | 0 | my ( $begi, $gcnt ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||
| 375 | 0 | my ( %data, @keys ); | |||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 378 | 0 | @data{ @_ } = @{ $self->[_DATA] }{ @_ }; | |||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | if ( scalar( keys %data ) == scalar( @_ ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 380 | # @_ has zero duplicates, finish up | ||||||||||||||||||||||||||||||||
| 381 | 0 | @keys = map "$_", @_; | |||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||
| 383 | else { | ||||||||||||||||||||||||||||||||
| 384 | # @_ has duplicate keys, try again the long way | ||||||||||||||||||||||||||||||||
| 385 | 0 | my ( $DATA, $key ) = ( $self->[_DATA] ); | |||||||||||||||||||||||||||||||
| 386 | 0 | %data = (); | |||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | 0 | $key = shift; | |||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | next if ( exists $data{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 390 | 0 | push @keys, "$key"; | |||||||||||||||||||||||||||||||
| 391 | 0 | $data{ $key } = $DATA->{ $key }; | |||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | else { | ||||||||||||||||||||||||||||||||
| 396 | 0 | @keys = ${ $self->[_GCNT] } | |||||||||||||||||||||||||||||||
| 397 | 0 | ? grep defined($_), @{ $self->[_KEYS] } | |||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | : @{ $self->[_KEYS] }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | 0 | %data = %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $self->clear() if $params->{'flush'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | 0 | bless [ \%data, \@keys, {}, \$begi, \$gcnt ], ref $self; | |||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | # flush ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 409 | # flush ( ) | ||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 412 | 0 | shift()->clone( { flush => 1 }, @_ ); | |||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | # iterator ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 416 | # iterator ( "query string" ) | ||||||||||||||||||||||||||||||||
| 417 | # iterator ( ) | ||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | 2 | ▶ | sub iterator { | ||||||||||||||||||||||||||||||
|
Subroutine
iterator: called CC=4 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 420 | 2 | my ( $self, @keys ) = @_; | |||||||||||||||||||||||||||||||
| 421 | 2 | my $data = $self->[_DATA]; | |||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | if ( ! @keys ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 424 | 2 | @keys = $self->keys; | |||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | ▶ | elsif ( @keys == 1 && $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
@keys == 1 and $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@keys == 1 and $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@keys == 1
$keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table0%0/3
A and B
A= @keys == 1B= $keys[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||
| 427 | 0 | @keys = $self->keys($keys[0]); | |||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | 6 | ▶ | return sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 431 | 6 | ▶ | return unless @keys; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 432 | 4 | my $key = shift @keys; | |||||||||||||||||||||||||||||||
| 433 | 4 | return ( $key => $data->{ $key } ); | |||||||||||||||||||||||||||||||
| 434 | 2 | }; | |||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||
| 437 | # keys ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 438 | # keys ( "query string" ) | ||||||||||||||||||||||||||||||||
| 439 | # keys ( ) | ||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | 2 | ▶ | sub keys { | ||||||||||||||||||||||||||||||
|
Subroutine
keys: called CC=7 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 442 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||
| 444 | 2 | ▶ | if ( @_ == 1 && $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@_ == 1
$_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||
| 445 | 0 | $self->_find({ getkeys => 1 }, @_); | |||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||
| 447 | elsif ( wantarray ) { | ||||||||||||||||||||||||||||||||
| 448 | 2 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 449 | 0 | my $data = $self->[_DATA]; | |||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | return map { exists $data->{ $_ } ? $_ : undef } @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||
| 452 | 2 | ${ $self->[_GCNT] } | |||||||||||||||||||||||||||||||
| 453 | 0 | ? grep defined($_), @{ $self->[_KEYS] } | |||||||||||||||||||||||||||||||
| 454 | 2 | ▶ | : @{ $self->[_KEYS] }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||
| 456 | else { | ||||||||||||||||||||||||||||||||
| 457 | 0 | scalar CORE::keys %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | # pairs ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 462 | # pairs ( "query string" ) | ||||||||||||||||||||||||||||||||
| 463 | # pairs ( ) | ||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||
| 465 | 3 | ▶ | sub pairs { | ||||||||||||||||||||||||||||||
|
Subroutine
pairs: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 466 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||
| 468 | 3 | ▶ | if ( @_ == 1 && $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@_ == 1
$_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table33%1/3
A and B
A= @_ == 1B= $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||
| 469 | 0 | $self->_find(@_); | |||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||
| 471 | elsif ( wantarray ) { | ||||||||||||||||||||||||||||||||
| 472 | 3 | my $data = $self->[_DATA]; | |||||||||||||||||||||||||||||||
| 473 | 3 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 474 | 0 | return map { $_ => $data->{ $_ } } @_; | |||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||
| 476 | 3 | ${ $self->[_GCNT] } | |||||||||||||||||||||||||||||||
| 477 | 0 | ? map { $_ => $data->{ $_ } } grep defined($_), @{ $self->[_KEYS] } | |||||||||||||||||||||||||||||||
| 478 | 3 | ▶ | : map { $_ => $data->{ $_ } } @{ $self->[_KEYS] }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||
| 480 | else { | ||||||||||||||||||||||||||||||||
| 481 | 0 | scalar CORE::keys %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | # values ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 486 | # values ( "query string" ) | ||||||||||||||||||||||||||||||||
| 487 | # values ( ) | ||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | sub values { | ||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 490 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | if ( @_ == 1 && $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
MC/DC0%0/2
@_ == 1 and $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
@_ == 1
$_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
Truth table0%0/3
A and B
A= @_ == 1B= $_[0] =~ /^(?:key|val)[ ]+\S\S?[ ]+\S/
| |||||||||||||||||||||||||||||||||
| 493 | 0 | $self->_find({ getvals => 1 }, @_); | |||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||
| 495 | elsif ( wantarray ) { | ||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 497 | 0 | return @{ $self->[_DATA] }{ @_ }; | |||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||
| 499 | 0 | ${ $self->[_GCNT] } | |||||||||||||||||||||||||||||||
| 500 | 0 | ? @{ $self->[_DATA] }{ grep defined($_), @{ $self->[_KEYS] } } | |||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | : @{ $self->[_DATA] }{ @{ $self->[_KEYS] } }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||
| 503 | else { | ||||||||||||||||||||||||||||||||
| 504 | 0 | scalar CORE::keys %{ $self->[_DATA] }; | |||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||
| 508 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 509 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 510 | ## assign, mdel, mexists, mget, mset, purge, sort | ||||||||||||||||||||||||||||||||
| 511 | ## | ||||||||||||||||||||||||||||||||
| 512 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | # assign ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | sub assign { | ||||||||||||||||||||||||||||||
|
Subroutine
assign: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 517 | 0 | $_[0]->clear; shift()->mset(@_); | |||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||
| 520 | # mdel ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | sub mdel { | ||||||||||||||||||||||||||||||
|
Subroutine
mdel: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 523 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 524 | 0 | my ( $data, $cnt, $key ) = ( $self->[_DATA], 0 ); | |||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 527 | 0 | $key = shift; | |||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | $cnt++, $self->delete( $key ) if ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||
| 531 | 0 | $cnt; | |||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | # mexists ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | sub mexists { | ||||||||||||||||||||||||||||||
|
Subroutine
mexists: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 537 | 0 | my ( $data ) = @{ shift() }; | |||||||||||||||||||||||||||||||
| 538 | 0 | my $key; | |||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 541 | 0 | $key = shift; | |||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | return '' unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||
| 545 | 0 | 1; | |||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||
| 548 | # mget ( key [, key, ... ] ) | ||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | sub mget { | ||||||||||||||||||||||||||||||
|
Subroutine
mget: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 551 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | @_ ? @{ $self->[_DATA] }{ @_ } : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | # mset ( key, value [, key, value, ... ] ) | ||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | sub mset { | ||||||||||||||||||||||||||||||
|
Subroutine
mset: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 559 | 0 | my ( $data, $keys ) = @{ shift() }; | |||||||||||||||||||||||||||||||
| 560 | 0 | my $key; | |||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | push @{ $keys }, "$key" unless ( exists $data->{ $key = shift } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 564 | 0 | $data->{ $key } = shift; | |||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | defined wantarray ? scalar CORE::keys %{ $data } : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||
| 570 | # purge ( ) | ||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | sub purge { | ||||||||||||||||||||||||||||||
|
Subroutine
purge: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 573 | 0 | my ( $data, $keys, $indx, $begi, $gcnt ) = @{ $_[0] }; | |||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||
| 575 | # purge in-place for minimum memory consumption | ||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | if ( ${ $gcnt } ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 578 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||
| 579 | 0 | for my $key ( @{ $keys } ) { | |||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | $keys->[ $i++ ] = $key if ( defined $key ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||
| 582 | 0 | splice @{ $keys }, $i; | |||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||
| 585 | 0 | ${ $begi } = ${ $gcnt } = 0; | |||||||||||||||||||||||||||||||
| 586 | 0 | %{ $indx } = (); | |||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||
| 588 | 0 | return; | |||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||
| 591 | # sort ( "BY key [ ASC | DESC ] [ ALPHA ]" ) | ||||||||||||||||||||||||||||||||
| 592 | # sort ( "BY val [ ASC | DESC ] [ ALPHA ]" ) | ||||||||||||||||||||||||||||||||
| 593 | # sort ( "[ ASC | DESC ] [ ALPHA ]" ) # same as "BY val ..." | ||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | sub sort { | ||||||||||||||||||||||||||||||
|
Subroutine
sort: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 596 | 0 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||
| 597 | 0 | my ( $by_key, $alpha, $desc ) = ( 0, 0, 0 ); | |||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | if ( length $request ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | $by_key = 1 if ( $request =~ /\bkey\b/i ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | $alpha = 1 if ( $request =~ /\balpha\b/i ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | $desc = 1 if ( $request =~ /\bdesc\b/i ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||
| 605 | # Return sorted keys, leaving the data intact. | ||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||
| 607 | 0 | my $keys = ${ $self->[_GCNT] } | |||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | ? [ grep defined($_), @{ $self->[_KEYS] } ] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 609 | : $self->[_KEYS]; | ||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | if ( defined wantarray ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | if ( $by_key ) { # by key | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if ( $alpha ) { ( $desc ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 614 | 0 | ? CORE::sort { $b cmp $a } @{ $keys } | |||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | : CORE::sort { $a cmp $b } @{ $keys }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||
| 617 | else { ( $desc ) | ||||||||||||||||||||||||||||||||
| 618 | 0 | ? CORE::sort { $b <=> $a } @{ $keys } | |||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | : CORE::sort { $a <=> $b } @{ $keys }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||
| 622 | else { # by value | ||||||||||||||||||||||||||||||||
| 623 | 0 | my $d = $self->[_DATA]; | |||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if ( $alpha ) { ( $desc ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 625 | 0 | ? CORE::sort { $d->{$b} cmp $d->{$a} } @{ $keys } | |||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | : CORE::sort { $d->{$a} cmp $d->{$b} } @{ $keys }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||
| 628 | else { ( $desc ) | ||||||||||||||||||||||||||||||||
| 629 | 0 | ? CORE::sort { $d->{$b} <=> $d->{$a} } @{ $keys } | |||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | : CORE::sort { $d->{$a} <=> $d->{$b} } @{ $keys }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||
| 635 | # Sort keys in-place otherwise, in void context. | ||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||
| 637 | elsif ( $by_key ) { # by key | ||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | if ( $alpha ) { ( $desc ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 639 | 0 | ? $self->_reorder( CORE::sort { $b cmp $a } @{ $keys } ) | |||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | : $self->_reorder( CORE::sort { $a cmp $b } @{ $keys } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||
| 642 | else { ( $desc ) | ||||||||||||||||||||||||||||||||
| 643 | 0 | ? $self->_reorder( CORE::sort { $b <=> $a } @{ $keys } ) | |||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | : $self->_reorder( CORE::sort { $a <=> $b } @{ $keys } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||
| 647 | else { # by value | ||||||||||||||||||||||||||||||||
| 648 | 0 | my $d = $self->[_DATA]; | |||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if ( $alpha ) { ( $desc ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 650 | 0 | ? $self->_reorder( CORE::sort { $d->{$b} cmp $d->{$a} } @{ $keys } ) | |||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | : $self->_reorder( CORE::sort { $d->{$a} cmp $d->{$b} } @{ $keys } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||
| 653 | else { ( $desc ) | ||||||||||||||||||||||||||||||||
| 654 | 0 | ? $self->_reorder( CORE::sort { $d->{$b} <=> $d->{$a} } @{ $keys } ) | |||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | : $self->_reorder( CORE::sort { $d->{$a} <=> $d->{$b} } @{ $keys } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | sub _reorder { | ||||||||||||||||||||||||||||||
|
Subroutine
_reorder: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 661 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 662 | 0 | @{ $self->[_KEYS] } = @_; | |||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||
| 664 | 0 | ${ $self->[_BEGI] } = ${ $self->[_GCNT] } = 0; | |||||||||||||||||||||||||||||||
| 665 | 0 | %{ $self->[_INDX] } = (); | |||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||
| 667 | 0 | return; | |||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||
| 670 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 671 | ## ---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||
| 672 | ## Sugar API, mostly resembles https://redis.io/commands#string primitives. | ||||||||||||||||||||||||||||||||
| 673 | ## | ||||||||||||||||||||||||||||||||
| 674 | ############################################################################### | ||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||
| 676 | # append ( key, string ) | ||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | sub append { | ||||||||||||||||||||||||||||||
|
Subroutine
append: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 679 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | length( $data->{ $key } .= $_[2] // '' ); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] // ""
MC/DC0%0/1
$_[2] // ""
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||
| 685 | # decr ( key ) | ||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | sub decr { | ||||||||||||||||||||||||||||||
|
Subroutine
decr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 688 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||
| 691 | 0 | --$data->{ $key }; | |||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||
| 694 | # decrby ( key, number ) | ||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | sub decrby { | ||||||||||||||||||||||||||||||
|
Subroutine
decrby: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 697 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | $data->{ $key } -= $_[2] || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] || 0
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||
| 703 | # incr ( key ) | ||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||
| 705 | 0 | ▶ | sub incr { | ||||||||||||||||||||||||||||||
|
Subroutine
incr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 706 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||
| 709 | 0 | ++$data->{ $key }; | |||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||
| 712 | # incrby ( key, number ) | ||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||
| 714 | 0 | ▶ | sub incrby { | ||||||||||||||||||||||||||||||
|
Subroutine
incrby: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 715 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | $data->{ $key } += $_[2] || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] || 0
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||
| 721 | # getdecr ( key ) | ||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | sub getdecr { | ||||||||||||||||||||||||||||||
|
Subroutine
getdecr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 724 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 725 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | $data->{ $key }-- // 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$data->{$key}-- // 0
MC/DC0%0/1
$data->{$key}-- // 0
$data->{$key}--
Truth table0%0/2
A
A= $data->{$key}--
| |||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||
| 730 | # getincr ( key ) | ||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | sub getincr { | ||||||||||||||||||||||||||||||
|
Subroutine
getincr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 733 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | $data->{ $key }++ // 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$data->{$key}++ // 0
MC/DC0%0/1
$data->{$key}++ // 0
$data->{$key}++
Truth table0%0/2
A
A= $data->{$key}++
| |||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||
| 739 | # getset ( key, value ) | ||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | sub getset { | ||||||||||||||||||||||||||||||
|
Subroutine
getset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 742 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | push @{ $_[0]->[_KEYS] }, "$key" unless ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||
| 745 | 0 | my $old = $data->{ $key }; | |||||||||||||||||||||||||||||||
| 746 | 0 | $data->{ $key } = $_[2]; | |||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||
| 748 | 0 | $old; | |||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||
| 751 | # setnx ( key, value ) | ||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | sub setnx { | ||||||||||||||||||||||||||||||
|
Subroutine
setnx: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 754 | 0 | my ( $key, $data ) = ( $_[1], @{ $_[0] } ); | |||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | return 0 if ( exists $data->{ $key } ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||
| 757 | 0 | $data->{ $key } = $_[2]; | |||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||
| 759 | 0 | 1; | |||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||
| 762 | # len ( key ) | ||||||||||||||||||||||||||||||||
| 763 | # len ( ) | ||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | sub len { | ||||||||||||||||||||||||||||||
|
Subroutine
len: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 766 | ( defined $_[1] ) | ||||||||||||||||||||||||||||||||
| 767 | ? length $_[0]->[_DATA]{ $_[1] } | ||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | : scalar CORE::keys %{ $_[0]->[_DATA] }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||
| 771 | { | ||||||||||||||||||||||||||||||||
| 772 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||
| 774 | 4 | *{ __PACKAGE__.'::new' } = \&TIEHASH; | |||||||||||||||||||||||||||||||
| 775 | 4 | *{ __PACKAGE__.'::set' } = \&STORE; | |||||||||||||||||||||||||||||||
| 776 | 4 | *{ __PACKAGE__.'::get' } = \&FETCH; | |||||||||||||||||||||||||||||||
| 777 | 4 | *{ __PACKAGE__.'::delete' } = \&DELETE; | |||||||||||||||||||||||||||||||
| 778 | 4 | *{ __PACKAGE__.'::exists' } = \&EXISTS; | |||||||||||||||||||||||||||||||
| 779 | 4 | *{ __PACKAGE__.'::clear' } = \&CLEAR; | |||||||||||||||||||||||||||||||
| 780 | 4 | *{ __PACKAGE__.'::pop' } = \&POP; | |||||||||||||||||||||||||||||||
| 781 | 4 | *{ __PACKAGE__.'::push' } = \&PUSH; | |||||||||||||||||||||||||||||||
| 782 | 4 | *{ __PACKAGE__.'::shift' } = \&SHIFT; | |||||||||||||||||||||||||||||||
| 783 | 4 | *{ __PACKAGE__.'::unshift' } = \&UNSHIFT; | |||||||||||||||||||||||||||||||
| 784 | 4 | *{ __PACKAGE__.'::splice' } = \&SPLICE; | |||||||||||||||||||||||||||||||
| 785 | 4 | *{ __PACKAGE__.'::del' } = \&delete; | |||||||||||||||||||||||||||||||
| 786 | 4 | *{ __PACKAGE__.'::merge' } = \&mset; | |||||||||||||||||||||||||||||||
| 787 | 4 | *{ __PACKAGE__.'::vals' } = \&values; | |||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||
| 790 | # For on-demand hash-like dereferencing. | ||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||
| 792 | package # hide from rpm | ||||||||||||||||||||||||||||||||
| 793 | MCE::Shared::Ordhash::_href; | ||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | sub TIEHASH { $_[1] } | ||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||
| 797 | 4 | 1; | |||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||
| 799 | __END__ | ||||||||||||||||||||||||||||||||