NAME
Net::IP::Identifier::Binode - A node in the binary tree
VERSION
version 0.086
SYNOPSIS
use Net::IP::Identifier::Binode;
DESCRIPTION
Net::IP::Identifier::Binode represents a single node in a binary tree. The branches off the node are zero and one. The node may also carry a $payload. Any of these may be set via arguments to new or through accessors.
Accessors (or arguments to new)
- zero( [ $new ] )
-
Set or get the zero branch. If new is defined, it must be a Net::IP::Identifier::Binode.
- one( [ $new ] )
-
Set or get the one branch. If new is defined, it must be a Net::IP::Identifier::Binode.
- payload( [ $new ] )
-
Set or get the payload attached to this node. new can be anything. It's a good idea to create a Local::Payload object to hold the $payload.
Methods
- $node = $root->construct($path);
-
Construct a branch of the tree out to $path. New child nodes are created as necessary. The return value is the node at $path.
- follow($path, $callback, [ @extra ] );
-
Descend the binary tree, following $path. $path should be a string where the length represents the number of levels to descend, false characters ('0's and spaces) follow the zero branch, and true characters follow the one branch.
$callback must be a code reference, which will be called at each visited node. It is called thusly:
$callback->($self, $path, $level, @extra);
where $self if the current node, $path is the original path, $level is the current index into $path, and @extra are just passed from the along original call.
The callback must return true to stop following (abort the descent), or false to continue normally.
- traverse_width_first($callback, [ @extra ] ); =item traverse_depth_first($callback, [ @extra ] );
-
Traverse the binary tree, either width or depth first.
$callback must be a code reference, which will be called at each visited node. It is called thusly:
$callback->($self, $level, @extra);
where $self if the current node, $level is the current depth (starting with 0 at the entry node), and @extra are just passed from the along original call.
The callback must return true to stop following (abort the descent), or false to continue normally.
SEE ALSO
AUTHOR
Reid Augustin <reid@hellosix.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Reid Augustin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.