Heap::Elem::Ref(3pm)
π Heap::Elem::Ref β the perl manual page, but make it cute β¨
okay bestie, gather round, because this is Heap::Elem::Ref(3pm) from the User Contributed Perl Documentation and it's genuinely so much simpler than it sounds π«Ά
β¨ NAME β¨
Heap::Elem::Ref β Object Reference Heap Elements π
like. that's it. that's the name. object references, but they get to live on a heap.
πΈ SYNOPSIS πΈ
use Heap::Elem::Ref( RefElem );
use Heap::Fibonacci;
my $heap = Heap::Fibonacci->new;
my $elem;
foreach $i ( 1..100 ) {
$obj = myObject->new( $i );
$elem = RefElem( $obj );
$heap->add( $elem );
}
while( defined( $elem = $heap->extract_top ) ) {
# assume that myObject object have a method I<printable>
print "Smallest is ", $elem->val->printable, "\n";
}
see how we're just yeeting a hundred objects into a Fibonacci heap and popping them out smallest-first? iconic behaviour honestly π
π¦ DESCRIPTION π¦
so, Heap::Elem::Ref exists to wrap object reference values into an element that a heap can actually manage for you. that's the whole job. it's giving personal assistant for your objects π
here's the deal, no cap: every referenced object must have a method called cmp that can compare itself against any of the other objects that have references sitting on the same heap. those comparisons have to be consistent with normal arithmetic β like, don't be weird about it, the ordering has to actually make sense β¨
the top of the heap will have the smallest element (according to cmp) that's still remaining. so the littlest one comes out first, every time.
and if you're out here wanting the heap to always hand you the largest element instead? go look at Heap::Elem::RefRev, that's literally what it's for π
the details of the Elem interface are described in Heap::Elem.
the details of using a Heap interface are described in Heap.
π AUTHOR π
John Macdonald, john@perlwolf.com β king behaviour, thank you for your service π
π COPYRIGHT π
Copyright 1998-2007, O'Reilly & Associates.
This code is distributed under the same copyright terms as perl itself.
π SEE ALSO π
and that's the whole page bestie, you ate it π this was perl v5.36.0, dated 2022-10-22, and the page itself is Heap::Elem::Ref(3pm) β now go wrap some objects and sort them, you've got this π«Άβ¨
π¦ where this page comes from
- ubuntu noble: libheap-perl 0.80-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libheap-perl 0.80-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libheap-perl 0.80-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms