| 1 | package Data::Range::Compare::Stream::Iterator::Consolidate::OverlapAsColumn; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base qw(Data::Range::Compare::Stream::Iterator::Consolidate); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Data::Range::Compare::Stream::Iterator::Array; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use constant NEW_ARRAY_ITERATOR_FROM=>'Data::Range::Compare::Stream::Iterator::Array'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use constant NEW_CHILD_CONSOLIDATOR_FROM=>'Data::Range::Compare::Stream::Iterator::Consolidate::OverlapAsColumn'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 44 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 44 | my ($class,$it,$cmp,%args)=@_; | |||||||||||||||||||||||||||
| 15 | 44 | ▶ | croak('Required Arguments are: $iterator,$compare') unless defined($cmp); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 44 | my $self=$class->SUPER::new($it,compare=>$cmp,buffer=>[],%args); | |||||||||||||||||||||||||||
| 17 | 44 | return $self; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 50 | ▶ | sub get_child { $_[0]->{consolidator} } | ||||||||||||||||||||||||||
|
Subroutine
get_child: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub delete_from_root { | ||||||||||||||||||||||||||
|
Subroutine
delete_from_root: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 2 | my ($self)=@_; | |||||||||||||||||||||||||||
| 24 | 2 | ▶ | if($self->has_child) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | my $child=$self->get_child; | |||||||||||||||||||||||||||
| 26 | 1 | delete $child->{root_iterator}; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 2 | ▶ | if($self->is_child) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 2 | my $root=$self->get_root; | |||||||||||||||||||||||||||
| 30 | 2 | delete @{$root}{qw(iterator_array consolidator)}; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 4 | ▶ | sub get_child_column_id { | ||||||||||||||||||||||||||
|
Subroutine
get_child_column_id: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 4 | my ($self)=@_; | |||||||||||||||||||||||||||
| 36 | 4 | ▶ | return undef unless $self->has_child; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 4 | $self->get_child->get_column_id; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 88 | ▶ | sub on_consolidate { | ||||||||||||||||||||||||||
|
Subroutine
on_consolidate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 88 | my ($self,$new_range,$last_range,$next_range)=@_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 88 | my $cmp=$self->{compare}; | |||||||||||||||||||||||||||
| 44 | 88 | my $iterator; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 88 | ▶ | if(defined($self->{iterator_array})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 61 | $iterator=$self->{iterator_array}; | |||||||||||||||||||||||||||
| 48 | 61 | $iterator->insert_range($next_range); | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 27 | $iterator=$self->{iterator_array}=$self->NEW_ARRAY_ITERATOR_FROM->new(sorted=>1); | |||||||||||||||||||||||||||
| 51 | 27 | $iterator->insert_range($next_range); | |||||||||||||||||||||||||||
| 52 | 27 | my $consolidator=$self->{consolidator}=$self->NEW_CHILD_CONSOLIDATOR_FROM->new($iterator,$cmp); | |||||||||||||||||||||||||||
| 53 | 27 | $consolidator->{root_iterator}=$self; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 34 | ▶ | sub get_root_column_id { | ||||||||||||||||||||||||||
|
Subroutine
get_root_column_id: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 34 | my ($self)=@_; | |||||||||||||||||||||||||||
| 60 | 34 | ▶ | return $self->get_root->get_column_id if $self->is_child; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $self->get_column_id | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 369 | ▶ | sub is_child { defined($_[0]->{root_iterator}) } | ||||||||||||||||||||||||||
|
Subroutine
is_child: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub is_root { !$_[0]->is_child } | ||||||||||||||||||||||||||
|
Subroutine
is_root: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 11 | ▶ | sub has_child { defined($_[0]->{iterator_array}) } | ||||||||||||||||||||||||||
|
Subroutine
has_child: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 3 | ▶ | sub has_root { defined($_[0]->get_root)} | ||||||||||||||||||||||||||
|
Subroutine
has_root: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 181 | ▶ | sub get_compare { $_[0]->{compare} } | ||||||||||||||||||||||||||
|
Subroutine
get_compare: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 220 | ▶ | sub get_root { | ||||||||||||||||||||||||||
|
Subroutine
get_root: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 220 | my ($self)=@_; | |||||||||||||||||||||||||||
| 74 | 220 | $self->{root_iterator}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 476 | ▶ | sub has_next { | ||||||||||||||||||||||||||
|
Subroutine
has_next: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 476 | my ($self)=@_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 476 | ▶ | return 1 if $#{$self->{buffer}}!=-1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 373 | ▶ | return 1 if $self->SUPER::has_next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 256 | ▶ | if($self->is_child) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 181 | my $cmp=$self->get_compare; | |||||||||||||||||||||||||||
| 85 | 181 | my $root=$self->get_root; | |||||||||||||||||||||||||||
| 86 | 181 | ▶ | if($root->SUPER::has_next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 20 | $root->push_to_buffer; | |||||||||||||||||||||||||||
| 88 | 20 | ▶ | return 1 if $#{$self->{buffer}}!=-1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 244 | return 0; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 5 | ▶ | sub get_current_result { $_[0]->{current_result} } | ||||||||||||||||||||||||||
|
Subroutine
get_current_result: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 88 | ▶ | sub get_next { | ||||||||||||||||||||||||||
|
Subroutine
get_next: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 88 | my ($self)=@_; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 88 | ▶ | if($#{$self->{buffer}}==-1 and $self->SUPER::has_next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$#{$$self{"buffer"};} == -1 and $self->SUPER::has_next
MC/DC50%1/2
$#{$$self{"buffer"};} == -1 and $self->SUPER::has_next
$#{$$self{"buffer"};} == -1
$self->SUPER::has_next
Truth table66%2/3
A and B
A= $#{$$self{"buffer"};} == -1B= $self->SUPER::has_next
| |||||||||||||||||||||||||||||
| 100 | 33 | $self->push_to_buffer; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 88 | my $result=shift @{$self->{buffer}}; | |||||||||||||||||||||||||||
| 103 | 88 | $self->{current_result}=$result; | |||||||||||||||||||||||||||
| 104 | 88 | return $result; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 13 | ▶ | sub buffer_count { 1 + $#{$_[0]->{buffer}} } | ||||||||||||||||||||||||||
|
Subroutine
buffer_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | sub get_buffer { $_[0]->{buffer} } | ||||||||||||||||||||||||||
|
Subroutine
get_buffer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 252 | ▶ | sub iterator_has_next { $_[0]->{iterator}->has_next } | ||||||||||||||||||||||||||
|
Subroutine
iterator_has_next: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 98 | ▶ | sub push_to_buffer { | ||||||||||||||||||||||||||
|
Subroutine
push_to_buffer: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 98 | my ($self)=@_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 98 | my $overlapping_range; | |||||||||||||||||||||||||||
| 118 | 98 | ▶ | if(defined($self->{last_range})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 38 | $overlapping_range=$self->{last_range}; | |||||||||||||||||||||||||||
| 120 | 38 | $self->{last_range}=undef; | |||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||
| 122 | 60 | $overlapping_range=$self->{iterator}->get_next; | |||||||||||||||||||||||||||
| 123 | 60 | $self->{last_range}=$overlapping_range; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 98 | ▶ | return 0 unless defined($overlapping_range); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 98 | my $result=$overlapping_range; | |||||||||||||||||||||||||||
| 128 | 98 | my $pushed_to_child=0; | |||||||||||||||||||||||||||
| 129 | 98 | ▶ | if($self->iterator_has_next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 66 | ▶ | OVERLAP_CHECK: while($self->iterator_has_next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 129 | my $next_range=$self->{iterator}->get_next; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 129 | ▶ | if($overlapping_range->overlap($next_range)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 88 | $overlapping_range=$overlapping_range->get_overlapping_range([$overlapping_range,$next_range]); | |||||||||||||||||||||||||||
| 137 | 88 | $self->on_consolidate($overlapping_range,$result,$next_range); | |||||||||||||||||||||||||||
| 138 | 88 | $pushed_to_child++; | |||||||||||||||||||||||||||
| 139 | 88 | $self->{last_range}=undef; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 41 | $self->{last_range}=$next_range; | |||||||||||||||||||||||||||
| 144 | 41 | last OVERLAP_CHECK; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||
| 149 | 32 | $self->{last_range}=undef; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 98 | ▶ | if($pushed_to_child) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 45 | my $child=$self->get_child; | |||||||||||||||||||||||||||
| 154 | 45 | $child->push_to_buffer; | |||||||||||||||||||||||||||
| 155 | 45 | ▶ | $self->{compare}->insert_consolidator($child) unless defined($child->get_column_id); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 98 | push @{$self->{buffer}},$self->RESULT_CLASS->new($result,$result,$result); | |||||||||||||||||||||||||||
| 160 | 98 | return 1; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 3 | 1; | |||||||||||||||||||||||||||