Heap::Elem::Num(3pm)

πŸ’– Heap::Elem::Num β€” the perl manual page, but make it bestie ✨

okay so this is Heap::Elem::Num(3pm), straight out of the User Contributed Perl Documentation, and it's literally just numeric heap elements πŸ’…


🌸 NAME 🌸

Heap::Elem::Num β€” Numeric Heap Elements. that's it, that's the whole name, slay πŸŽ€


✨ SYNOPSIS ✨

here's the vibe, copy-paste ready, no cap:

use Heap::Elem::Num( NumElem );
use Heap::Fibonacci;

my $heap = Heap::Fibonacci->new;
my $elem;

foreach $i ( 1..100 ) {
    $elem = NumElem( $i );
    $heap->add( $elem );
}

while( defined( $elem = $heap->extract_top ) ) {
    print "Smallest is ", $elem->val, "\n";
}

look at her go πŸ¦‹ making a heap, yeeting 100 numbers in, pulling them back out smallest-first. main character energy fr fr.


πŸ‘‘ DESCRIPTION πŸ‘‘

so Heap::Elem::Num is the little wrapper that takes a plain numeric value and dresses it up as an element so a heap can manage it 🫢 like, the number needs a glow-up to hang out on the heap, and this module is the stylist.

the top of the heap will have the smallest element still remaining. yes, smallest, that's the whole point bestie, min-heap behaviour, periodt πŸ’…

πŸ’€ heads up: if you actually wanted the largest element to come out first, go look at Heap::Elem::NumRev instead. don't come for me, that's just how it is.

the deets of the Elem interface itself? those live over in Heap::Elem β€” go read that if you want the full lore.

and the deets of actually using a Heap interface? those are in Heap. go read that one too.


🌈 AUTHOR 🌈

John Macdonald, john@perlwolf.com β€” shoutout to the legend who wrote this, we love you, we stan πŸ’œ


Copyright 1998-2007, O'Reilly & Associates.

This code is distributed under the same copyright terms as perl itself. (iykyk, same terms as perl, that's the whole deal ✨)


πŸ”₯ SEE ALSO πŸ”₯


one last thing bestie β€” grab the smallest, not the biggest. if you wanted biggest you're in the wrong manpage and I will be sending you to Heap::Elem::NumRev(3) πŸ™ˆ

and that's a wrap on this lil page πŸ’– it's from perl v5.36.0, dated 2022-10-22, and it lives at Heap::Elem::Num(3pm). love that for her. mwah 🫢

πŸ“¦ where this page comes from