Tree::RB::Node(3pm)

πŸ“¦
version 0.500006 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Tree::RB::Node πŸ’–

okay bestie so real talk: this is Tree::RB::Node, straight out of the User Contributed Perl Documentation (that's the 3pm section of the manual, iykyk). it's a whole lil page about one class, and we're gonna go through every single bit of it together. grab a snack. πŸ“


✨ NAME ✨

Tree::RB::Node β€” it's a node class for implementing Red/Black trees. that's the whole job. that's the vibe. πŸ‘‘


🌸 VERSION 🌸

This document describes Tree::RB::Node version 0.500006.


πŸ¦‹ SYNOPSIS πŸ¦‹

here's how you actually touch this thing in the wild, bestie:

use Tree::RB;

my $tree = Tree::RB->new;
$tree->put('France'  => 'Paris');
$tree->put('England' => 'London');

my $node = $tree->delete('France'); # $node is a Tree::RB::Node object
print $node->key; # 'France'
print $node->val; # 'Paris'

see how delete handed back a whole Tree::RB::Node object? that's the moment. main character energy fr fr. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

A Tree::RB tree is made up of nodes, and every one of those nodes is an object of type Tree::RB::Node. that's it. that's the structure. little node besties holding hands in a tree. 🌈


πŸ’œ INTERFACE πŸ’œ

A Tree::RB::Node object supports the following methods β€” and we are listing all of them, no skips, no shortcuts:

🌟 new()

Creates and returns a new node. fresh node, just dropped. ✨

🌟 key([KEY])

Get/set the key of the node. this is literally what the nodes are sorted by in the tree, so like, it matters a lot.

🌟 val([VALUE])

Get/set the value of the node. and the value? can be any scalar. go wild.

🌟 color([COLOR])

Get/set the color of the node. valid colors are the constants RED and BLACK, which are exported by Tree::RB::Node::_Constants. red or black, no in-between, that's the rule πŸŽ€

🌟 parent([PARENT])

Get/set the parent of the node, which must be another Tree::RB::Node object.

🌟 left([NODE])

Get/set the left child node of the node, which must be another Tree::RB::Node object.

🌟 right([NODE])

Get/set the right child node of the node, which must be another Tree::RB::Node object.

🌟 min()

Returns the node with the minimal key starting from this node. smol key, big energy.

🌟 max()

Returns the node with the maximal key starting from this node. biggest key, iconic behavior.

🌟 leaf()

Returns the first leaf node found starting from this node, using a depth first, left to right search.

🌟 successor()

Returns the node with the smallest key larger than this node's key, or "undef" if it is the node with the maximal key.

🌟 predecessor()

Returns the node with the greatest key smaller than this node's key, or "undef" if it is the node with the minimal key.

🌟 as_lol([NODE])

Returns a list of lists representing the tree whose root is either NODE if NODE is specified, or this node otherwise.

this is lowkey perfect for printing a tree, and here's the snippet that proves it (heads up: this assumes that Tree::DAG_Node is also installed):

use strict;
use Tree::DAG_Node;
use Tree::RB;

my $t = Tree::RB->new;

foreach (qw/the rain in spain falls mainly in the plains/) {
    $t->put($_, "${_} val");
}

my $tree = Tree::DAG_Node->lol_to_tree( $t->root->as_lol );
$, = "\n";
print @{ $tree->draw_ascii_tree };

and it will print this:

                      |
                   <B:rain>
               /-------------------\
               |                   |
             <R:in>             <B:the>
        /-----------\            /------\
        |           |            |      |
    <B:falls>   <B:mainly>   <R:spain> <*>
      /---\    /------\        /---\
      |   |    |      |        |   |
     <*> <*>  <*> <R:plains>  <*> <*>
                    /---\
                    |   |
                   <*> <*>

look at that. art. 🎨 we love a tree that draws itself.

🌟 strip([$callback])

Strips off all nodes under this node. and if a callback is specified, it will be called once for each node that is detached, with the detached node as its sole argument. so the callback gets fed every single node it takes out. no ghosting. πŸ’€


🫢 DEPENDENCIES 🫢

None.


πŸ™ˆ INCOMPATIBILITIES πŸ™ˆ

None reported.


😭 BUGS AND LIMITATIONS 😭

Please report any bugs or feature requests to "bug-tree-rb-node@rt.cpan.org", or through the web interface at <http://rt.cpan.org>.

bestie if you find a bug, tell the maintainer, don't just suffer in silence πŸ’–

πŸ‘‘ AUTHOR πŸ‘‘

Arun Prasad "<arunbear@cpan.org>"

Some documentation has been borrowed from Benjamin Holzman's Tree::RedBlack::Node. shoutout to the original, we love credit where credit is due 🌸


Copyright (c) 2007, Arun Prasad "<arunbear@cpan.org>". All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.


πŸ’€ DISCLAIMER OF WARRANTY πŸ’€

okay this next part is the scary all-caps legal bit, and no, I'm not softening a single word of it, because it's literally the warranty terms. read it. it matters. fr fr.

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


aaaand that's the whole page, bestie, you ate it πŸ“βœ¨ this was perl v5.36.0, dated 2022-11-19, and it's the Tree::RB::Node(3pm) page β€” go forth and balance your trees πŸ’…πŸ¦‹

πŸ“¦ where this page comes from