Fix resize function

This commit is contained in:
Justin Ethier 2019-06-25 18:20:48 -04:00
parent af2008cbcf
commit 364d2594b8

View file

@ -91,16 +91,21 @@
) )
(define (%queue-resize! q) (define (%queue-resize! q)
(write "TODO: resize the queue")(newline) ;; (write "TODO: resize the queue")(newline)
; ;; TODO: assumes we already have the lock ;; TODO: assumes we already have the lock
; ;; TODO: error if size is larger than fixnum?? ;; TODO: error if size is larger than fixnum??
; (let ((old-store (q:store q)) (let* ((old-start (q:start q))
; (new-store (make-vector (* (vector-length old-store) 2) #f))) (old-end (q:end q))
; (q:set-size! q 0) (old-store (q:store q))
; (let loop ((i (vector-length old-store))) (new-store (make-vector (* (vector-length old-store) 2) #f)))
; (when (not (zero? i)) (q:set-start! q 0)
; (%queue-add! q (vector-ref (q:set-end! q 0)
; (loop (- i 1))))) (q:set-store! q new-store)
(let loop ((i 0)
(start old-start))
(when (not (= i (vector-length old-store)))
(%queue-add! q (vector-ref old-store start))
(loop (+ i 1) (inc start (vector-length old-store))))))
) )
;- queue-remove! - remove item (when to block? would be nice if we can block until an item becomes available) ;- queue-remove! - remove item (when to block? would be nice if we can block until an item becomes available)