diff options
-rw-r--r-- | chickadee/array-list.scm | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/chickadee/array-list.scm b/chickadee/array-list.scm index 2208471..da450c8 100644 --- a/chickadee/array-list.scm +++ b/chickadee/array-list.scm @@ -106,23 +106,24 @@ (let loop ((i 0)) (when (< i n) (if (equal? item (vector-ref v i)) - (if fast? - ;; Fast: Swap the last element with the element to be - ;; deleted. Constant time but does not preserve - ;; order. - (let ((last (- n 1))) - (vector-set! v i (vector-ref v last)) - (vector-set! v last #f)) - ;; Slow: Shift all elements to the left. Linear time - ;; but preserves order. - (let shift ((j (+ i 1))) - (if (= j n) - (vector-set! v j #f) - (begin - (vector-set! v (- j 1) (vector-ref v j)) - (shift (+ j 1)))))) - (loop (+ i 1))))) - (set-array-list-size! array-list (- n 1)))) + (begin + (if fast? + ;; Fast: Swap the last element with the element to be + ;; deleted. Constant time but does not preserve + ;; order. + (let ((last (- n 1))) + (vector-set! v i (vector-ref v last)) + (vector-set! v last #f)) + ;; Slow: Shift all elements to the left. Linear time + ;; but preserves order. + (let shift ((j (+ i 1))) + (if (= j n) + (vector-set! v j #f) + (begin + (vector-set! v (- j 1) (vector-ref v j)) + (shift (+ j 1)))))) + (set-array-list-size! array-list (- n 1))) + (loop (+ i 1))))))) (define (array-list-clear! array-list) (let ((size (array-list-size array-list)) |