Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

tree::redblack(3pm) [debian man page]

RedBlack(3pm)						User Contributed Perl Documentation					     RedBlack(3pm)

NAME
Tree::RedBlack - Perl implementation of Red/Black tree, a type of balanced tree. SYNOPSIS
use Tree::RedBlack; my $t = new Tree::RedBlack; $t->insert(3, 'cat'); $t->insert(4, 'dog'); my $v = $t->find(4); my $min = $t->min; my $max = $t->max; $t->delete(3); $t->print; DESCRIPTION
This is a perl implementation of the Red/Black tree algorithm found in the book "Algorithms", by Cormen, Leiserson & Rivest (more commonly known as "CLR" or "The White Book"). A Red/Black tree is a binary tree which remains "balanced"- that is, the longest length from root to a node is at most one more than the shortest such length. It is fairly efficient; no operation takes more than O(lg(n)) time. A Tree::RedBlack object supports the following methods: new () Creates a new RedBlack tree object. root () Returns the root node of the tree. Note that this will either be undef if no nodes have been added to the tree, or a Tree::RedBlack::Node object. See the Tree::RedBlack::Node manual page for details on the Node object. cmp (&) Use this method to set a comparator subroutine. The tree defaults to lexical comparisons. This subroutine should be just like a comparator subroutine to sort, except that it doesn't do the $a, $b trick; the two elements to compare will just be the first two items on the stack. insert ($;$) Adds a new node to the tree. The first argument is the key of the node, the second is its value. If a node with that key already exists, its value is replaced with the given value and the old value is returned. Otherwise, undef is returned. delete ($) The argument should be either a node object to delete or the key of a node object to delete. WARNING!!! THIS STILL HAS BUGS!!! find ($) Searches the tree to find the node with the given key. Returns the value of that node, or undef if a node with that key isn't found. Note, in particular, that you can't tell the difference between finding a node with value undef and not finding a node at all. If you want to determine if a node with a given key exists, use the node method, below. node ($) Searches the tree to find the node with the given key. Returns that node object if it is found, undef otherwise. The node object is a Tree::RedBlack::Node object. min () Returns the node with the minimal key. max () Returns the node with the maximal key. AUTHOR
Benjamin Holzman <bholzman@earthlink.net> SEE ALSO
Tree::RedBlack::Node perl v5.10.0 2008-07-31 RedBlack(3pm)

Check Out this Related Man Page

Blt_TreeCreateNode(3)					      BLT Library Procedures					     Blt_TreeCreateNode(3)

__________________________________________________________________________________________________________________________________________________

NAME
Blt_TreeCreateNode - Creates a node in a tree data object. SYNOPSIS
#include <bltTree.h> Blt_TreeNode Blt_TreeCreateNode(tree, parent, name, position) ARGUMENTS
Blt_Tree tree (in) Tree containing the parent node. Blt_TreeNode parent (in) Node in which to insert the new child. const char *name (in) Node label. If NULL, a label will automatically be generated. int position (in) Position in the parent's list of children to insert the new node. _________________________________________________________________ DESCRIPTION
This procedure creates a new node is a tree data object. The node is initially empty, but data values can be added with Blt_TreeSetValue. Each node has a serial number that identifies it within the tree. No two nodes in the same tree will ever have the same ID. You can find a node's ID with Blt_TreeNodeId. The arguments are as follows: tree The tree containing the parent node. parent Node in which the new child will be inserted. name Label of the new node. If name is NULL, a label in the form "node0", "node1", etc. will automatically be generated. Name can be any string. Labels are non-unique. A parent can contain two nodes with the same label. Nodes can be relabeled using Blt_TreeRe- labelNode. position Position the parent's list of children to insert the new node. For example, if position is 0, then the new node is prepended to the beginning of the list. If position is -1, then the node is appended onto the end of the parent's list. RETURNS
The new node returned is of type Blt_TreeNode. It's a token that can be used with other routines to add/delete data values or children nodes. EXAMPLE
The following example creates a new node from the root node. Blt_Tree token; Blt_TreeNode root, node; if (Blt_TreeGetToken(interp, "myTree", &token) != TCL_OK) { return TCL_ERROR; } root = Blt_TreeRootNode(token); node = Blt_TreeCreateNode(token, root, "myNode", -1); NOTIFICATIONS
Blt_TreeCreateNode can trigger tree notify events. You can be notified whenever a node is created by using the Blt_TreeCreateNotifyHan- dler. A callback routine is registered that will be automatically invoked whenever a new node is added via Blt_TreeCreateNode to the tree. KEYWORDS
tree, token BLT
2.4 Blt_TreeCreateNode(3)
Man Page