     [ right ] dip data-nth ; inline
 
 : data-set-nth ( entry n heap -- )
-    [ [ >>index drop ] [ ] 2bi ] dip
+    [ [ swap index<< ] 2keep ] dip
     data>> set-nth-unsafe ; inline
 
 : data-push ( entry heap -- n )
     dup heap-size [
-        swap 2dup data>> ensure 2drop data-set-nth
-    ] [
-    ] bi ; inline
+        swap
+        [ data>> ensure 2drop ]
+        [ data-set-nth ] 2bi
+    ] keep ; inline
 
 : data-first ( heap -- entry )
     data>> first ; inline

    ] if ; inline recursive

: down-heap ( m heap -- )
    2dup left-bounds-check? [ 2drop ] [ (down-heap) ] if ; inline recursive

PRIVATE>

M: heap heap-push* ( value key heap -- entry )
    [ <entry> dup ] [ data-push ] [ ] tri up-heap ;

: heap-push ( value key heap -- ) heap-push* drop ;



GENERIC: heap-compare ( entry1 entry2 heap -- ? )

: entry<=> ( entry1 entry2 -- <=> )
    { entry entry } declare [ key>> ] compare ; inline

M: min-heap heap-compare drop entry<=> +gt+ eq? ;

M: max-heap heap-compare drop entry<=> +lt+ eq? ;

: heap-bounds-check? ( m heap -- ? )
    heap-size >= ; inline
