diff options
author | David Thompson <dthompson2@worcester.edu> | 2020-09-29 12:31:14 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2020-09-29 12:31:14 -0400 |
commit | fea6f5d467affbd699ef70aeb3cf69af1629bebe (patch) | |
tree | ce8ba4800a2c11ffbb7570ae553ddfd4aa1843b6 | |
parent | 6adcc3f7de0b24ee5d4d1ba4599b15049a7b6dcf (diff) |
array-list: Fix the bug fix in array-list-delete! procedure.
Ugh!!!!
-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)) |