]> gitweb.factorcode.org Git - factor.git/commitdiff
heaps: fix slurp-heap to allow modifying the heap while slurping.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 Dec 2014 16:53:48 +0000 (08:53 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 Dec 2014 16:53:48 +0000 (08:53 -0800)
basis/heaps/heaps.factor

index 27b53860ff646276b9eb95b915c55e7e12515d2d..87e7176ba8950e6a1be388cc9d946c14020a6f93 100644 (file)
@@ -147,13 +147,14 @@ M: heap heap-pop*
 M: heap heap-pop
     [ data-first >entry< ] [ heap-pop* ] bi ;
 
-: heap-pop-all ( heap -- alist )
-    check-heap [ heap-size ] keep
-    '[ _ heap-pop swap 2array ] replicate ;
+: slurp-heap ( ... heap quot: ( ... value key -- ... ) -- ... )
+    [ check-heap ] dip
+    [ drop '[ _ heap-empty? ] ]
+    [ '[ _ heap-pop @ ] until ] 2bi ; inline
 
-: slurp-heap ( heap quot: ( value key -- ) -- )
-    [ check-heap [ heap-size ] keep ] dip
-    '[ _ heap-pop @ ] times ; inline
+: heap-pop-all ( heap -- alist )
+    [ heap-size <vector> ] keep
+    [ swap 2array suffix! ] slurp-heap { } like ;
 
 ERROR: bad-heap-delete ;