NAME
Net::IP::Identifier::Binode - A node in the binary tree
VERSION
version 0.111
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
In the following methods, any references to $path mean a string consisting of true and false characters (usually ones and zeroes) which defines the path to follow to get to a particular node of the tree. The length of $path represents the number of levels to descend. False characters ('0's) follow the zero branch, and true characters follow the one branch.
- $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.
- $node->follow($path, $callback, [ @extra ] );
-
Descend the binary tree, following $path. $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 is the current node, $path is the original path, $level is the current index into $path, and @extra are just passed along from the original call.
The callback must return true to stop following (abort the descent), or false to continue normally.
- $node->traverse_width_first($callback, [ @extra ] );
- $node->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 node. It is called thusly:
$callback->($self, $level, @extra);
where $self is the current node, $level is the current depth (starting with 0 at the entry node), and @extra are just passed along from the 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.