Tree::Binary::XS - Perl extension for manipulating binary tree structure
use Tree::Binary::XS; my $tree = Tree::Binary::XS->new({ by_key => 'id' }); $tree->insert({ foo => 'bar', id => 11 }); $tree->insert([{ foo => 'bar', id => 11 }, ... ]); $ret->exists(10); $ret->exists({ id => 10, 'name' => 'Bob' }); # Use specified key instead of the key from payload $tree->insert(10, { foo => 'bar' }); # to insert multiple keys one time. @ret = $tree->insert_those([{ id => 10, 'name' => 'Bob' }, { id => 3, 'name' => 'John' }, { id => 2, 'name' => 'Hank' } ]); $tree->update(10, { foo => 'bar' }) $n = $tree->search(10); $tree->exists(10); $tree->exists({ foo => 'bar' , id => 10 }); $tree->inorder_traverse(sub { my ($key, $node) = @_; }); $tree->postorder_traverse(sub { my ($key, $node) = @_; }); $tree->preorder_traverse(sub { my ($key, $node) = @_; });
Please note this extension is not compatible with the Tree::Binary package, this module was redesigned and simplified the interface of manipulating tree structure.
The new method constructs the Tree object, you may specify the by_key option to let Tree::Binary::XS get the key from the inserted objects.
new
by_key
Once you've defined the by_key, you can simply pass the object to the insert method, for example:
$tree->insert({ id => 11, name => 'John', });
And 11 will be the key of the object.
11
If you want to specify another key to insert the object, you may pass the key as the first argument of the insert method.
key
insert
None by default.
Tree::Binary, Tree::Binary::Search
Lin Yo-an, <c9s@local>
Copyright (C) 2015 by Lin Yo-an
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Tree::Binary::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Binary::XS
CPAN shell
perl -MCPAN -e shell install Tree::Binary::XS
For more information on module installation, please visit the detailed CPAN module installation guide.