 ! Copyright (C) 2007, 2008 Ryan Murphy, Doug Coleman,
 ! Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math sequences arrays assocs sequences.private
-growable accessors math.order summary vectors fry combinators ;
+USING: accessors arrays assocs combinators fry growable kernel
+kernel.private math math.order math.private sequences
+sequences.private summary vectors ;
+
 IN: heaps
 
 GENERIC: heap-push* ( value key heap -- entry )

    [ dup heap-pop swap 2array ]
    produce nip ;

: slurp-heap ( heap quot: ( elt -- ) -- )
    over heap-empty? [ 2drop ] [
        [ [ heap-pop drop ] dip call ] [ slurp-heap ] 2bi
    ] if ; inline recursive


ERROR: bad-heap-delete ;

M: bad-heap-delete summary
    drop "Invalid entry passed to heap-delete" ;

: entry>index ( entry heap -- n )
    over heap>> eq? [ bad-heap-delete ] unless
    index>> { fixnum } declare ; inline

M: heap heap-delete ( entry heap -- )
    [ entry>index ] [ ] bi
