SkewHeap - A fast heap structure for Perl
version 0.01
use SkewHeap; my $heap = SkewHeap->new(sub{ $a <=> $b }); $heap->put(42); $heap->put(35); $heap->put(200); $heap->put(62); $heap->top; # 35 $heap->size; # 4 $heap->take; # 35 $heap->take; # 42 $heap->take; # 62 $heap->take; # 200 $heap->merge($other_skewheap);
A skew heap is a memory efficient, self-adjusting heap (or priority queue) with an amortized performance of O(log n) (or better). SkewHeap is implemented in C (using Inline::C).
SkewHeap
The key feature of a skew heap is the ability to quickly and efficiently merge two heaps together.
Creates a new SkewHeap which will be sorted in ascending order using the comparison subroutine passed in. This sub has the same semantics as Perl's sort, returning -1 if $a < $b, 1 if $a $b>, or 0 if $a == $b.
sort
$a < $b
$a
$a == $b
Returns the number of elements in the heap.
Returns the next element which would be returned by "take" without removing it from the heap.
Inserts a new element into the heap.
Removes and returns the next element from the heap.
Destructively merges another heap into itself. After calling merge, the second heap is empty and the first holds all elements from both heaps.
Jeff Ober <sysread@fastmail.fm>
This software is copyright (c) 2018 by Jeff Ober.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install SkewHeap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SkewHeap
CPAN shell
perl -MCPAN -e shell install SkewHeap
For more information on module installation, please visit the detailed CPAN module installation guide.