Tree::RB

Perl implementation of the Red/Black tree, a type of balanced binary search tree
Download

Tree::RB Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Arun Prasaad
  • Publisher web site:
  • http://search.cpan.org/~arunbear/

Tree::RB Tags


Tree::RB Description

Perl implementation of the Red/Black tree, a type of balanced binary search tree Tree::RB is a Perl implementation of the Red/Black tree, a type of balanced binary search tree.A tied hash interface is also provided to allow ordered hashes to be used.See the Wikipedia article at http://en.wikipedia.org/wiki/Red-black_tree for more on Red/Black trees.SYNOPSIS use Tree::RB; my $tree = Tree::RB->new; $tree->put('France' => 'Paris'); $tree->put('England' => 'London'); $tree->put('Hungary' => 'Budapest'); $tree->put('Ireland' => 'Dublin'); $tree->put('Egypt' => 'Cairo'); $tree->put('Germany' => 'Berlin'); $tree->put('Alaska' => 'Anchorage'); # D'oh! $tree->delete('Alaska'); print $tree->get('Ireland'); # 'Dublin' print $tree->min->key; # 'Egypt' print $tree->max->key; # 'Ireland' print $tree->size; # 6 # print items, ordered by key my $it = $tree->iter; while(my $node = $it->next) { sprintf "key = %s, value = %s ", $node->key, $node->val; } # print items in reverse order $it = $tree->rev_iter; while(my $node = $it->next) { sprintf "key = %s, value = %s ", $node->key, $node->val; } # Hash interface tie my pital, 'Tree::RB'; # or do this to store items in descending order tie my pital, 'Tree::RB', sub { $_ cmp $_ }; $capital{'France'} = 'Paris'; $capital{'England'} = 'London'; $capital{'Hungary'} = 'Budapest'; $capital{'Ireland'} = 'Dublin'; $capital{'Egypt'} = 'Cairo'; $capital{'Germany'} = 'Berlin'; # print items in order while(my ($key, $val) = each pital) { printf "key = $key, value = $val "; } Requirements: · Perl


Tree::RB Related Software