TT#69200 Fix coding style

Change-Id: I4f5d0893199f26126c50f8c50b43592fe5d6d3aa
changes/61/35061/1
Guillem Jover 6 years ago
parent a551ce2246
commit f5921964d3

@ -72,30 +72,29 @@ sub itemcount {
} }
sub grouparray { sub grouparray {
my ($array_ptr, $case_insensitive) = @_;
my ($array_ptr,$case_insensitive) = @_; my $result = NGCP::BulkProcessor::Table->new();
my $result = NGCP::BulkProcessor::Table->new(); my $reducedarray = removeduplicates($array_ptr, $case_insensitive);
my $reducedarray = removeduplicates($array_ptr,$case_insensitive); my $sort_occurencecount_desc;
my $sort_occurencecount_desc;
if ($case_insensitive) {
$sort_occurencecount_desc = sub {
return ((lc($NGCP::BulkProcessor::Table::b->[1]) <=> lc($NGCP::BulkProcessor::Table::a->[1])) or (lc($NGCP::BulkProcessor::Table::a->[0]) cmp lc($NGCP::BulkProcessor::Table::b->[0])));
};
} else {
$sort_occurencecount_desc = sub {
return (($NGCP::BulkProcessor::Table::b->[1] <=> $NGCP::BulkProcessor::Table::a->[1]) or ($NGCP::BulkProcessor::Table::a->[0] cmp $NGCP::BulkProcessor::Table::b->[0]));
}; if ($case_insensitive) {
} $sort_occurencecount_desc = sub {
foreach my $element (@$reducedarray) { return ((lc($NGCP::BulkProcessor::Table::b->[1]) <=> lc($NGCP::BulkProcessor::Table::a->[1])) or
$result->addrow_ref([$element,itemcount($element,$array_ptr,$case_insensitive)]); (lc($NGCP::BulkProcessor::Table::a->[0]) cmp lc($NGCP::BulkProcessor::Table::b->[0])));
} };
$result->sortrows($sort_occurencecount_desc); } else {
return $result; $sort_occurencecount_desc = sub {
return (($NGCP::BulkProcessor::Table::b->[1] <=> $NGCP::BulkProcessor::Table::a->[1]) or
($NGCP::BulkProcessor::Table::a->[0] cmp $NGCP::BulkProcessor::Table::b->[0]));
};
}
foreach my $element (@{$reducedarray}) {
$result->addrow_ref([ $element, itemcount($element, $array_ptr, $case_insensitive) ]);
}
$result->sortrows($sort_occurencecount_desc);
return $result;
} }
sub reversearray { sub reversearray {
@ -136,7 +135,7 @@ sub _array_last {
} }
sub arrayeq { sub arrayeq {
my ($array_ptr1,$array_ptr2,$case_insensitive) = @_; my ($array_ptr1, $array_ptr2, $case_insensitive) = @_;
my $ubound1 = _array_last($array_ptr1) // -1; my $ubound1 = _array_last($array_ptr1) // -1;
my $ubound2 = _array_last($array_ptr2) // -1; my $ubound2 = _array_last($array_ptr2) // -1;
@ -144,162 +143,148 @@ sub arrayeq {
return 0 if $ubound1 != $ubound2; return 0 if $ubound1 != $ubound2;
if ($case_insensitive) { if ($case_insensitive) {
foreach my $i (0 .. $ubound1) { foreach my $i (0 .. $ubound1) {
if (lc($array_ptr1->[$i]) ne lc($array_ptr2->[$i])) { return 0 if lc $array_ptr1->[$i] ne lc $array_ptr2->[$i];
return 0;
} }
}
} else { } else {
foreach my $i (0 .. $ubound1) { foreach my $i (0 .. $ubound1) {
if ($array_ptr1->[$i] ne $array_ptr2->[$i]) { return 0 if $array_ptr1->[$i] ne $array_ptr2->[$i];
return 0;
} }
}
} }
return 1; return 1;
} }
sub seteq { sub seteq {
my ($array_ptr1, $array_ptr2, $case_insensitive) = @_;
my ($array_ptr1,$array_ptr2,$case_insensitive) = @_;
my $ubound1 = _array_last($array_ptr1) // -1; my $ubound1 = _array_last($array_ptr1) // -1;
my $ubound2 = _array_last($array_ptr2) // -1; my $ubound2 = _array_last($array_ptr2) // -1;
# every element of array1 must be existent in array2 ... # every element of array1 must be existent in array2 ...
foreach my $i (0 .. $ubound1) { foreach my $i (0 .. $ubound1) {
if (not contains($array_ptr1->[$i],$array_ptr2,$case_insensitive)) { return 0 if not contains($array_ptr1->[$i], $array_ptr2, $case_insensitive);
return 0;
} }
} # ... and every element of array2 must be existent in array1
# ... and every element of array2 must be existent in array1 foreach my $i (0 .. $ubound2) {
foreach my $i (0 .. $ubound2) { return 0 if not contains($array_ptr2->[$i], $array_ptr1, $case_insensitive);
if (not contains($array_ptr2->[$i],$array_ptr1,$case_insensitive)) {
return 0;
} }
}
return 1;
return 1;
} }
sub setcontains { sub setcontains {
my ($array_ptr1, $array_ptr2, $case_insensitive) = @_;
my ($array_ptr1,$array_ptr2,$case_insensitive) = @_;
my $ubound1 = _array_last($array_ptr1) // -1; my $ubound1 = _array_last($array_ptr1) // -1;
# every element of array1 must be existent in array2: # every element of array1 must be existent in array2:
foreach my $i (0 .. $ubound1) { foreach my $i (0 .. $ubound1) {
if (not contains($array_ptr1->[$i],$array_ptr2,$case_insensitive)) { return 0 if not contains($array_ptr1->[$i], $array_ptr2, $case_insensitive);
return 0;
} }
}
return 1;
return 1;
} }
sub filter { sub filter {
my ($array_ptr1, $array_ptr2, $case_insensitive) = @_;
my ($array_ptr1,$array_ptr2,$case_insensitive) = @_;
my $ubound1 = _array_last($array_ptr1); my $ubound1 = _array_last($array_ptr1);
my $ubound2 = _array_last($array_ptr2); my $ubound2 = _array_last($array_ptr2);
return [] if not defined $ubound1; return [] if not defined $ubound1;
return $array_ptr1 if not defined $ubound2; return $array_ptr1 if not defined $ubound2;
my @result = (); my @result = ();
# every element of array1 must be existent in array2 ... # every element of array1 must be existent in array2 ...
foreach my $i (0 .. $ubound1) { foreach my $i (0 .. $ubound1) {
if (contains($array_ptr1->[$i],$array_ptr2,$case_insensitive)) { if (contains($array_ptr1->[$i], $array_ptr2, $case_insensitive)) {
push @result,$array_ptr1->[$i]; push @result, $array_ptr1->[$i];
}
} }
}
return \@result;
return \@result;
} }
sub getroundrobinitem { sub getroundrobinitem {
my ($array_ptr, $recentindex) = @_;
my ($array_ptr,$recentindex) = @_; if (defined $array_ptr and ref $array_ptr eq 'ARRAY') {
if (defined $array_ptr and ref $array_ptr eq 'ARRAY') { my $size = scalar @{$array_ptr};
my $size = (scalar @$array_ptr);
if ($size == 1) { if ($size == 1) {
return (@{$array_ptr}[0],0); return (@{$array_ptr}[0], 0);
} elsif ($size > 1) { } elsif ($size > 1) {
if (!defined $recentindex or $recentindex < 0) { if (not defined $recentindex or $recentindex < 0) {
$recentindex = -1; $recentindex = -1;
} }
my $newindex = ($recentindex + 1) % $size; my $newindex = ($recentindex + 1) % $size;
return (@{$array_ptr}[$newindex],$newindex); return (@{$array_ptr}[$newindex], $newindex);
}
} }
}
return (undef,undef);
return (undef, undef);
} }
sub getrandomitem { sub getrandomitem {
my ($array_ptr) = @_;
my ($array_ptr) = @_; if (defined $array_ptr and ref $array_ptr eq 'ARRAY') {
if (defined $array_ptr and ref $array_ptr eq 'ARRAY') { my $size = (scalar @{$array_ptr});
my $size = (scalar @$array_ptr);
if ($size == 1) { if ($size == 1) {
return (@{$array_ptr}[0],0); return (@{$array_ptr}[0], 0);
} elsif ($size > 1) { } elsif ($size > 1) {
my $newindex = int(rand($size)); my $newindex = int rand $size;
return (@{$array_ptr}[$newindex],$newindex); return (@{$array_ptr}[$newindex], $newindex);
}
} }
}
return (undef,undef);
return (undef, undef);
} }
sub array_to_map { sub array_to_map {
my ($array_ptr, $get_key_code, $get_value_code, $mode) = @_;
my ($array_ptr,$get_key_code,$get_value_code,$mode) = @_;
my $map = {}; my $map = {};
my @keys = (); my @keys = ();
my @values = (); my @values = ();
if (defined $array_ptr and ref $array_ptr eq 'ARRAY' and if (defined $array_ptr and ref $array_ptr eq 'ARRAY' and
defined $get_key_code and ref $get_key_code eq 'CODE') { defined $get_key_code and ref $get_key_code eq 'CODE') {
if (not (defined $get_value_code and ref $get_value_code eq 'CODE')) { if (not (defined $get_value_code and ref $get_value_code eq 'CODE')) {
$get_value_code = sub { return shift; }; $get_value_code = sub { return shift; };
} }
$mode = lc($mode); $mode = lc $mode;
if (not ($mode eq 'group' or $mode eq 'first' or $mode eq 'last')) { if (not ($mode eq 'group' or $mode eq 'first' or $mode eq 'last')) {
$mode = 'group'; $mode = 'group';
} }
foreach my $item (@$array_ptr) { foreach my $item (@{$array_ptr}) {
my $key = &$get_key_code($item); my $key = &$get_key_code($item);
next unless defined $key;
next unless defined $key;
my $value = &$get_value_code($item); my $value = &$get_value_code($item);
next unless defined $value; next unless defined $value;
if (not exists $map->{$key}) { if (not exists $map->{$key}) {
if ($mode eq 'group') { if ($mode eq 'group') {
$map->{$key} = [ $value ]; $map->{$key} = [ $value ];
} else { } else {
$map->{$key} = $value; $map->{$key} = $value;
} }
push(@keys,$key); push @keys, $key;
} else { } else {
if ($mode eq 'group') { if ($mode eq 'group') {
push(@{$map->{$key}}, $value); push @{$map->{$key}}, $value;
} elsif ($mode eq 'last') { } elsif ($mode eq 'last') {
$map->{$key} = $value; $map->{$key} = $value;
} }
} }
push(@values,$value); push @values, $value;
} }
} }
return ($map,\@keys,\@values);
return ($map, \@keys, \@values);
} }
sub _hash_size { sub _hash_size {
@ -318,9 +303,7 @@ sub mapeq {
my $key_count1 = _hash_size($map_ref1); my $key_count1 = _hash_size($map_ref1);
my $key_count2 = _hash_size($map_ref2); my $key_count2 = _hash_size($map_ref2);
if ($key_count1 != $key_count2) { return 0 if $key_count1 != $key_count2;
return 0;
}
if ($case_insensitive) { if ($case_insensitive) {
for my $key (keys %{$map_ref2}) { for my $key (keys %{$map_ref2}) {

Loading…
Cancel
Save