Skip to content

Commit

Permalink
use for_list in Tree.pm and TreeNode.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnlaffan committed Sep 6, 2024
1 parent 6a06b7c commit 3a3e28e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 4 additions & 5 deletions lib/Biodiverse/Tree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use POSIX qw /floor ceil/;
use feature 'refaliasing';
no warnings 'experimental::refaliasing';

use experimental 'for_list';

use English qw ( -no_match_vars );

Expand Down Expand Up @@ -527,8 +528,7 @@ sub get_node_length_hash {

my %len_hash;
my $node_hash = $self->get_node_hash;
foreach my $node_name ( keys %$node_hash ) {
my $node_ref = $node_hash->{$node_name};
foreach my ($node_name, $node_ref) ( %$node_hash ) {
$len_hash{$node_name} = $node_ref->get_length;
}

Expand Down Expand Up @@ -3353,7 +3353,7 @@ sub get_nti_expected_mean {

my $s = $self->get_terminal_element_count;
my $cb_bnok_one_arg = $self->get_bnok_ratio_callback_one_val(r => $r, s => $s);
my $cb_bnok_two_arg = $self->get_bnok_ratio_callback_two_val(r => $r, s => $s);
# my $cb_bnok_two_arg = $self->get_bnok_ratio_callback_two_val(r => $r, s => $s);

\my %tip_count_cache
= $self->get_cached_value_dor_set_default_aa (NODE_TIP_COUNT_CACHE => {});
Expand All @@ -3363,8 +3363,7 @@ sub get_nti_expected_mean {

my $sum;
my $node_hash = $self->get_node_hash;
foreach my $name (keys %$node_hash) {
my $node = $node_hash->{$name};
foreach my ($name, $node) (%$node_hash) {
my $se
= $tip_count_cache{$name}
//= $node->get_terminal_element_count;
Expand Down
8 changes: 5 additions & 3 deletions lib/Biodiverse/TreeNode.pm
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package Biodiverse::TreeNode;
use 5.022;
use 5.036;
use strict;
use warnings;
no warnings 'recursion';

use feature 'refaliasing';
no warnings 'experimental::refaliasing';

use experimental 'for_list';

use English qw ( -no_match_vars );
use Ref::Util qw { :all };

Expand Down Expand Up @@ -2769,8 +2771,8 @@ sub _get_len_sum_by_tip_count_hash {
$hash->{$self->get_terminal_element_count} += $self->get_length;
foreach my $child ($self->get_children) {
my $ch_hash = $child->_get_len_sum_by_tip_count_hash;
foreach my $tc (keys %$ch_hash) {
$hash->{$tc} += $ch_hash->{$tc};
foreach my ($tc, $val) (%$ch_hash) {
$hash->{$tc} += $val;
}
}
$self->set_cached_value($cache_key => $hash);
Expand Down

0 comments on commit 3a3e28e

Please sign in to comment.