The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tree::Binary::XS - Perl extension for manipulating binary tree structure

SYNOPSIS

  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) = @_;
    });

DESCRIPTION

Please note this extension is not compatible with the Tree::Binary package, this module was redesigned and simplified the interface of manipulating tree structure.

FUNCTIONS

$tree = Tree::Binary::XS->new({ by_key => $field_name })

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.

$tree->insert(hashref $object)

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.

$tree->insert(IV key, hashref $object)

If you want to specify another key to insert the object, you may pass the key as the first argument of the insert method.

@ret = $tree->insert_those([ $obj1, $obj2, ... ])
$tree->update(IV key, $new_object)
$tree->exists(IV key)
$tree->exists(hashref $object)
$tree->search(IV key)
$tree->search(hashref $object)

Tree Traversal

$tree->postorder_traverse(sub { my ($key, $node) = @_; })
$tree->preorder_traverse(sub { my ($key, $node) = @_; })
$tree->inorder_traverse(sub { my ($key, $node) = @_; })

EXPORT

None by default.

SEE ALSO

Tree::Binary, Tree::Binary::Search

AUTHOR

Lin Yo-an, <c9s@local>

COPYRIGHT AND LICENSE

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:

Around line 138:

You forgot a '=back' before '=head1'