NAME
Net::IP::Identifier::Binode - A node in the binary tree
VERSION
version 0.054
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
- descend($path, [ $payload ] );
-
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.
To construct a branch of the tree, define $payload. New child nodes are created as necessary, and when the end of $path is reached, $payload is attached. To create the branch with nothing attached at the final node, pass undef as the $payload:
$root-node->descend($path, undef)
When not constructing a branch (no $payload element is passed), the return value is an array of each node along $path that contained a $payload, including the $payload of the final node. Checking for more than one node in the return array indicates which $payloads have 'parent' $payloads.
When constructing a branch ($payload is passed), each child branch below the final $path node is explored and any child node that contains a $payload is added to the return array. Checking for more than one payload in the return array indicates which branches of the binary tree have overlapping $payloads.
- children
-
Returns an array consisting of the current node (if this node has a $payload), and the nodes of all child branches that carry a $payload.
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.