yure
public text v1 · immutable#
# This should insert a node with 4 empty children
# however it fails...
#
sub insert {
my($tree, $value, $children) = @_;
unless($tree){ #build initial root
$tree= {}
}
my $branch = $tree;
my $child = $value % $children;
do{
if(!$branch->{VALUE}){
for my $index (0 .. $children-1) { #build node
$branch->{$index} = undef;
}
$branch->{VALUE} = $value;
$_[0] = $tree;
return;
}
}while($branch = $branch->{$child});
}