NAME
Tree::Create::Callback::ChildrenPerLevel - Create tree object by using a callback (and number of children per level)
VERSION
This document describes version 0.03 of Tree::Create::Callback::ChildrenPerLevel (from Perl distribution Tree-Create-Callback), released on 2016-04-01.
SYNOPSIS
use Tree::Create::Callback::ChildrenPerLevel qw(create_tree_using_callback);
use Tree::Object::Hash; # for nodes
# create a tree of height 4 containing 1 (root) + 3 + 10 + 7 nodes
my $tree = create_tree_using_callback(
sub {
my ($parent, $level, $seniority) = @_;
# we should return ($node)
return (Tree::Object::Hash->new);
},
[3, 10, 7],
);
DESCRIPTION
FUNCTIONS
create_tree_using_callback($cb, \@num_children_per_level) => obj
This is like Tree::Create::Callback's create_tree_using_callback
(in fact, it's implemented as a thin wrapper over it), except that the callback does not need to return:
($node, $num_children)
but only:
($node)
The $num_children
will be calculated by this function to satisfy total number of children per level specified in \@num_children_per_level
. So suppose \@num_children_per_level
is [10, 50, 25]
, then the root node will have 10 children, and each child node will have 50/10 = 5 children of their own, but only one out of two of these children will have a child because the number of children at the third level is only 25 (half of 50).
Specifying total number of children per level is sometimes more convenient than specifying number of children per node.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Tree-Create-Callback.
SOURCE
Source repository is at https://github.com/perlancar/perl-Tree-Create-Callback.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Tree-Create-Callback
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
Other Tree::Create::Callback
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.