heaps: change slurp-heap to slurp keys and values.
							parent
							
								
									ab3f3173af
								
							
						
					
					
						commit
						937f575735
					
				| 
						 | 
				
			
			@ -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." } ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue