heaps: change slurp-heap to slurp keys and values.
parent
ab3f3173af
commit
937f575735
|
|
@ -96,6 +96,5 @@ HELP: heap-delete
|
||||||
{ $side-effects "heap" } ;
|
{ $side-effects "heap" } ;
|
||||||
|
|
||||||
HELP: slurp-heap
|
HELP: slurp-heap
|
||||||
{ $values
|
{ $values { "heap" heap } { "quot" { $quotation ( value key -- ) } } }
|
||||||
{ "heap" heap } { "quot" quotation } }
|
{ $description "Removes entries from a heap and processes them with the quotation until the heap is empty." } ;
|
||||||
{ $description "Removes values from a heap and processes them with the quotation until the heap is empty." } ;
|
|
||||||
|
|
|
||||||
|
|
@ -189,9 +189,9 @@ ERROR: not-a-heap object ;
|
||||||
: check-heap ( heap -- heap )
|
: check-heap ( heap -- heap )
|
||||||
dup heap? [ not-a-heap ] unless ; inline
|
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 ] [
|
[ 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
|
] if ; inline recursive
|
||||||
|
|
||||||
: >min-heap ( assoc -- min-heap )
|
: >min-heap ( assoc -- min-heap )
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ IN: sorting.heap
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (heapsort) ( alist accum -- sorted-seq )
|
: (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>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue