| 1 | package TUI::Objects::NSSortedCollection; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Defines the class TNSSortedCollection | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 28 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||
| 9 | 28 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 28 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 28 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 28 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TNSSortedCollection | ||||||||||||||||||||||||||||
| 15 | new_TNSSortedCollection | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 28 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 28 | ▶ | use TUI::toolkit::Types qw( :types ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 28 | ▶ | use TUI::Objects::Const qw( ccNotFound ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 28 | ▶ | use TUI::Objects::NSCollection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub TNSSortedCollection() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub new_TNSSortedCollection { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TNSSortedCollection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 28 | extends TNSCollection; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # import global variables | ||||||||||||||||||||||||||||
| 30 | 28 | ▶ | use vars qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | %ITEMS | ||||||||||||||||||||||||||||
| 32 | 28 | ); | |||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 28 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 28 | *ITEMS = \%{ TNSCollection . '::ITEMS' }; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # public attributes | ||||||||||||||||||||||||||||
| 39 | 28 | has duplicates => ( is => 'rw', default => false ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 8 | ▶ | sub search { # $bool ($key|undef, \$index) | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 8 | state $sig = signature( | |||||||||||||||||||||||||||
| 43 | method => Object, | ||||||||||||||||||||||||||||
| 44 | pos => [Any, ScalarRef], | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | 8 | my ( $self, $key, $index_ref ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 47 | 8 | my $l = 0; | |||||||||||||||||||||||||||
| 48 | 8 | my $h = $self->{count} - 1; | |||||||||||||||||||||||||||
| 49 | 8 | my $res = false; | |||||||||||||||||||||||||||
| 50 | 8 | ▶ | while ( $l <= $h ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 11 | my $i = ( $l + $h ) >> 1; | |||||||||||||||||||||||||||
| 52 | 11 | my $item = $ITEMS{ $self->{items}->[$i] }; | |||||||||||||||||||||||||||
| 53 | 11 | my $c = $self->compare( $self->keyOf( $item ), $key ); | |||||||||||||||||||||||||||
| 54 | 11 | ▶ | if ( $c < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 7 | $l = $i + 1; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||
| 58 | 4 | $h = $i - 1; | |||||||||||||||||||||||||||
| 59 | 4 | ▶ | if ( $c == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 3 | $res = true; | |||||||||||||||||||||||||||
| 61 | 3 | ▶ | $l = $i unless $self->{duplicates}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } #/ while ( $l <= $h ) | ||||||||||||||||||||||||||||
| 65 | 8 | $$index_ref = $l; | |||||||||||||||||||||||||||
| 66 | 8 | return $res; | |||||||||||||||||||||||||||
| 67 | } #/ sub search | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub indexOf { # $index ($item|undef) | ||||||||||||||||||||||||||
|
Subroutine
indexOf: called CC=6 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 2 | state $sig = signature( | |||||||||||||||||||||||||||
| 71 | method => Object, | ||||||||||||||||||||||||||||
| 72 | pos => [Item], | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | 2 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 75 | 2 | my $i; | |||||||||||||||||||||||||||
| 76 | 2 | ▶ | if ( !$self->search( $self->keyOf( $item ), \$i ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 1 | return ccNotFound; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if ( $self->{duplicates} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | while ( $i < $self->{count} && $item ne $ITEMS{ $self->{items}->[$i] } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i < $self->{"count"} and $item ne $TUI::Objects::NSSortedCollection::ITEMS{$self->{"items"}[$i]}
MC/DC0%0/2
$i < $self->{"count"} and $item ne $TUI::Objects::NSSortedCollection::ITEMS{$self->{"items"}[$i]}
$i < $self->{"count"}
$item ne $TUI::Objects::NSSortedCollection::ITEMS{$self->{"items"}[$i]}
Truth table0%0/3
A and B
A= $i < $self->{"count"}B= $item ne $TUI::Objects::NSSortedCollection::ITEMS{$self->{"items"}[$i]}
| |||||||||||||||||||||||||||||
| 82 | 0 | $i++; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | return $i < $self->{count} ? $i : ccNotFound; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } #/ sub indexOf | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | ▶ | sub insert { # $index ($item|undef) | ||||||||||||||||||||||||||
|
Subroutine
insert: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 91 | method => Object, | ||||||||||||||||||||||||||||
| 92 | pos => [Item], | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | 4 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 95 | 4 | my $i; | |||||||||||||||||||||||||||
| 96 | 4 | ▶ | if ( !$self->search( $self->keyOf( $item ), \$i ) || $self->{duplicates} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->search($self->keyOf($item), \$i) or $self->{"duplicates"}
MC/DC0%0/2
not $self->search($self->keyOf($item), \$i) or $self->{"duplicates"}
not $self->search($self->keyOf($item), \$i)
$self->{"duplicates"}
Truth table66%2/3
not(A) or B
A= not $self->search($self->keyOf($item), \$i)B= $self->{"duplicates"}
| |||||||||||||||||||||||||||||
| 97 | 4 | $self->atInsert( $i, $item ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 4 | return $i; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 18 | ▶ | sub keyOf { # $key ($item|undef) | ||||||||||||||||||||||||||
|
Subroutine
keyOf: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 18 | state $sig = signature( | |||||||||||||||||||||||||||
| 104 | method => Object, | ||||||||||||||||||||||||||||
| 105 | pos => [Item], | ||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | 18 | my ( $self, $item ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 108 | 18 | return $item; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub compare { # $cmp ($key1, $key2) | ||||||||||||||||||||||||||
|
Subroutine
compare: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 113 | method => Object, | ||||||||||||||||||||||||||||
| 114 | pos => [Any, Any], | ||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||
| 116 | 0 | $sig->( @_ ); | |||||||||||||||||||||||||||
| 117 | 0 | return 0; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 28 | 1 | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||