Heap::Simple

Heap::Simple is a Perl module that contains easy to use and fast classic heaps.
Download

Heap::Simple Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Ton Hospel
  • Publisher web site:
  • http://search.cpan.org/~thospel/Tie-Cacher-0.09/Cacher.pm

Heap::Simple Tags


Heap::Simple Description

Heap::Simple is a Perl module that contains easy to use and fast classic heaps. Heap::Simple is a Perl module that contains easy to use and fast classic heaps.SYNOPSIS use Heap::Simple; # Create a heap my $heap = Heap::Simple->new; my $heap = Heap::Simple->new(%options); # Put data in the heap $heap->insert(@new_elements); # Put data in a "Object" or "Any" heap with a given key $heap->key_insert($key1, $element1, $key2, $element2, ...); # Extract the top value $element = $heap->extract_top; # croaks on an empty heap $element = $heap->extract_first; # returns undef on an empty heap # Get the top value but leave it in the heap $element = $heap->top; # croaks on an empty heap $element = $heap->first; # returns undef on an empty heap # Find the top key in the heap $top_key = $heap->top_key; # return infinity on an empty heap # croaks if there's no infinity $top_key = $heap->first_key; # returns undef on an empty heap # Ordered extract of all data whose key is not above a given value @elements = $heap->extract_upto($max_key); # Ordered extract of all data @elements = $heap->extract_all; # Empty the heap $heap->clear; # Find the number of elements $count = $heap->count; # Get all keys (not sorted) @keys = $heap->keys; # Get all values (not sorted) @values = $heap->values; # Find the key corresponding to a value $key = $heap->key($value); # Get/Set user_data $user_data = $heap->user_data; $old_data = $heap->user_data($new_data); # Get/Set infinity $infinity = $heap->infinity; $old_infinity = $heap->infinity($new_data); # Get the position of a key in an element $key_index = $heap->key_index; $key_name = $heap->key_name; $key_method = $heap->key_method; $key_function = $heap->key_function; # Return the value of several things that were set in new: $wrapped = $heap->wrapped; $max_count = $heap->max_count; $can_die = $heap->can_die; $dirty = $heap->dirty; $order = $heap->order; @elements = $heap->elements; $elements = $heap->elements; # Move all elements out of each heap in @heaps and into $heap $heap->absorb(@heaps); # As if doing a repeated $heap->insert $heap->key_absorb(@heaps); # As if doing a repeated $heap->key_insert # merge already sorted arrays into a new sorted array # This doesn't disturb the elements already in the heap my $merged_aref = $heap->merge_arrays($aref1, $aref2, ...); # Which class does the actual work ? $implementation = Heap::Simple->implementation;EXAMPLEWhen key and value are kept separate: use Heap::Simple; my $heap = Heap::Simple->new(elements => "Any"); $heap->key_insert(8, "bar"); $heap->key_insert(5, "foo"); # This will print foo (5 is the lowest key) print "First value is ", $heap->extract_top, "n"; $heap->key_insert(7, "baz"); # This will print baz (7 is the lowest key) print "Next value is ", $heap->extract_top, "n"; # This will print bar (8 is now the lowest key) print "Next value is ", $heap->extract_top, "n"; Requirements: · Perl


Heap::Simple Related Software