         pop* drop
     ] if ; inline
 
-M: heap heap-pop
-    [ data-first >entry< ] [ heap-pop* ] bi ;
+: heap-pop ( heap -- value key )
+    [ heap-peek ] [ heap-pop* ] bi ;
 
 : slurp-heap ( ... heap quot: ( ... value key -- ... ) -- ... )
     [ drop '[ _ heap-empty? ] ]

<PRIVATE

:: sift-up ( heap n -- )
    heap heap-size  :> end
    n heap data-nth :> tmp

    n dup left [ dup end < ] [
        dup 1 fixnum+fast
        dup end < [ 2dup heap data-compare ] [ f ] if
        [ nip ] [ drop ] if
        [ heap data-nth swap heap data-set-nth ]
        [ dup left ] bi
    ] while drop

    tmp over heap data-set-nth
    heap n rot sift-down ; inline

PRIVATE>

GENERIC: heap-push* ( value key heap -- entry )
GENERIC: heap-peek ( heap -- value key )
GENERIC: heap-pop* ( heap -- )
GENERIC: heap-delete ( entry heap -- )
GENERIC: heap-empty? ( heap -- ? )
GENERIC: heap-size ( heap -- n )
