Skip to content

Commit

Permalink
Indices: ensure calc_abc2 and 3 are run before calc_abc
Browse files Browse the repository at this point in the history
This will save some processing given calc_abc
can now adapt their results.
  • Loading branch information
shawnlaffan committed Feb 25, 2024
1 parent 17b477e commit 466eeaa
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/Biodiverse/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1023,15 +1023,20 @@ sub aggregate_calc_lists_by_type {
my @u_array = uniq @$array;
if ($type eq 'pre_calc'
and scalar @u_array
and any {$_ eq '_calc_abc_any'} @u_array
) {
# move first /calc_abc[23]?/ to front so
# _calc_abc_any can grab results
state $re = qr{^calc_abc\d?};
if ($u_array[0] !~ $re) {
my $iter = first_index {$_ =~ $re} @u_array;
if ($iter > 0) {
unshift @u_array, splice @u_array, $iter, 1;
# move first /calc_abc[23]/ to front so
# calc_abc and _calc_abc_any can grab results
# otherwise ensure calc_abc is at the front
# for _calc_abc_any
state $re = qr{^calc_abc[23]};
my $iter23 = first_index {$_ =~ $re} @u_array;
if ($iter23 > 0) {
unshift @u_array, splice @u_array, $iter23, 1;
}
else {
my $iter1 = first_index {$_ eq 'calc_abc'} @u_array;
if ($iter1 > 0) {
unshift @u_array, splice @u_array, $iter1, 1;
}
}
}
Expand Down

0 comments on commit 466eeaa

Please sign in to comment.