.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "RedBlack 3pm" .TH RedBlack 3pm "2022-10-22" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Tree::RedBlack \- Perl implementation of Red/Black tree, a type of balanced tree. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Tree::RedBlack; \& \& my $t = new Tree::RedBlack; \& $t\->insert(3, \*(Aqcat\*(Aq); \& $t\->insert(4, \*(Aqdog\*(Aq); \& my $v = $t\->find(4); \& my $min = $t\->min; \& my $max = $t\->max; \& $t\->delete(3); \& $t\->print; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a perl implementation of the Red/Black tree algorithm found in the book \&\*(L"Algorithms\*(R", by Cormen, Leiserson & Rivest (more commonly known as \*(L"\s-1CLR\*(R"\s0 or \&\*(L"The White Book\*(R"). A Red/Black tree is a binary tree which remains \*(L"balanced\*(R"\- 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. .PP A Tree::RedBlack object supports the following methods: .IP "new ()" 4 .IX Item "new ()" Creates a new RedBlack tree object. .IP "root ()" 4 .IX Item "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. .IP "cmp (&)" 4 .IX Item "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 \f(CW$a\fR, \f(CW$b\fR trick; the two elements to compare will just be the first two items on the stack. .IP "insert ($;$)" 4 .IX Item "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. .IP "delete ($)" 4 .IX Item "delete ($)" The argument should be either a node object to delete or the key of a node object to delete. \s-1WARNING\s0!!! \s-1THIS STILL HAS BUGS\s0!!! .IP "find ($)" 4 .IX Item "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. .IP "node ($)" 4 .IX Item "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. .IP "min ()" 4 .IX Item "min ()" Returns the node with the minimal key. .IP "max ()" 4 .IX Item "max ()" Returns the node with the maximal key. .SH "AUTHOR" .IX Header "AUTHOR" Benjamin Holzman .SH "SEE ALSO" .IX Header "SEE ALSO" Tree::RedBlack::Node