summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2020-04-12 21:56:21 -0400
committerDavid Thompson <dthompson2@worcester.edu>2020-04-12 21:56:21 -0400
commitb15a8b5be99df32e86af8bfb6f5dbdaacceda776 (patch)
tree797c7b54052f25b9bd6f2e6d28e73476b710d594
parentf2721b20704a0e5a4960d490d0ba465feccdf192 (diff)
heap: Fix heap-remove!
It totally trashed the underlying vector before, now it behaves properly.
-rw-r--r--chickadee/heap.scm5
1 files changed, 4 insertions, 1 deletions
diff --git a/chickadee/heap.scm b/chickadee/heap.scm
index db9bea9..3a7d17e 100644
--- a/chickadee/heap.scm
+++ b/chickadee/heap.scm
@@ -96,7 +96,8 @@
(let ((size (1- (heap-size heap)))
(< (heap-< heap)))
(define (finish hole)
- (heap-set! heap hole (heap-ref heap (heap-size heap)))
+ (heap-set! heap (heap-size heap) #f)
+ (heap-set! heap 0 #f)
(set-heap-size! heap size)
*unspecified*)
@@ -120,7 +121,9 @@
(if (< (heap-ref heap hole) (heap-ref heap child))
(finish hole)
(begin
+ (heap-set! heap 0 (heap-ref heap hole))
(heap-set! heap hole (heap-ref heap child))
+ (heap-set! heap child (heap-ref heap 0))
(loop child))))))))
(define (heap-clear! heap)