heaps: change slurp-heap to slurp keys and values.

db4
John Benediktsson 2014-12-01 15:14:25 -08:00
parent ab3f3173af
commit 937f575735
3 changed files with 5 additions and 6 deletions

View File

@ -96,6 +96,5 @@ HELP: heap-delete
{ $side-effects "heap" } ;
HELP: slurp-heap
{ $values
{ "heap" heap } { "quot" quotation } }
{ $description "Removes values from a heap and processes them with the quotation until the heap is empty." } ;
{ $values { "heap" heap } { "quot" { $quotation ( value key -- ) } } }
{ $description "Removes entries from a heap and processes them with the quotation until the heap is empty." } ;

View File

@ -189,9 +189,9 @@ ERROR: not-a-heap object ;
: check-heap ( heap -- heap )
dup heap? [ not-a-heap ] unless ; inline
: slurp-heap ( heap quot: ( elt -- ) -- )
: slurp-heap ( heap quot: ( value key -- ) -- )
[ check-heap ] dip over heap-empty? [ 2drop ] [
[ [ heap-pop drop ] dip call ] [ slurp-heap ] 2bi
[ [ heap-pop ] dip call ] [ slurp-heap ] 2bi
] if ; inline recursive
: >min-heap ( assoc -- min-heap )

View File

@ -8,7 +8,7 @@ IN: sorting.heap
<PRIVATE
: (heapsort) ( alist accum -- sorted-seq )
[ >min-heap ] [ [ [ push ] curry slurp-heap ] keep ] bi* ; inline
[ >min-heap ] [ [ [ nip push ] curry slurp-heap ] keep ] bi* ; inline
PRIVATE>