simplify code (no need for vector)

svn: r4756
This commit is contained in:
Eli Barzilay 2006-11-03 00:30:33 +00:00
parent 6c388f5fce
commit e69c62efde

View File

@ -256,30 +256,25 @@
;; finds the next leaf after the selected child, ;; finds the next leaf after the selected child,
;; using `inc' and `start' to control the direction of the traversal. ;; using `inc' and `start' to control the direction of the traversal.
(define/private (select-next inc start) (define/private (select-next inc start)
(let ([fst-selected (get-selected)]) (define fst-selected (get-selected))
(when fst-selected
(let loop ([item fst-selected]) (let loop ([item fst-selected])
(when item (when item
(let* ([parent (send item get-parent)] (let* ([parent (send item get-parent)]
[siblings (list->vector [siblings (if parent
(if parent
(send parent get-items) (send parent get-items)
(get-items)))]) (get-items))]
[siblings-len (length siblings)])
(let sibling-loop ([index (inc (find-index item siblings))]) (let sibling-loop ([index (inc (find-index item siblings))])
(cond (if (< -1 index siblings-len)
[(and (<= 0 index) (let ([child (find-first-leaf (list-ref siblings index)
(< index (vector-length siblings))) inc start)])
(let ([sibling (vector-ref siblings index)]) (if child
(cond (begin (send fst-selected select #f)
[(find-first-leaf sibling inc start)
=>
(λ (child)
(send fst-selected select #f)
(send child select #t) (send child select #t)
(open-parents child) (open-parents child)
(make-visible child))] (make-visible child))
[else (sibling-loop (inc index))]))] (sibling-loop (inc index))))
[else (loop parent)])))))))) (loop parent)))))))
;; find-first-leaf : item (int -> int) (vec -> int) ;; find-first-leaf : item (int -> int) (vec -> int)
;; finds the first child, using `inc' and `start' to control ;; finds the first child, using `inc' and `start' to control
@ -299,16 +294,14 @@
item] item]
[else #f]))) [else #f])))
;; find-index : tst (vectorof tst) -> int ;; find-index : tst (listof tst) -> int
;; returns the index of `item' in `vec' ;; returns the index of `item' in `lst'
(define/private (find-index item vec) (define/private (find-index item lst)
(let loop ([i 0]) (let loop ([i 0] [l lst])
(cond (cond [(null? l)
[(< i (vector-length vec)) (error 'find-index "didn't find ~e in ~e" item lst)]
(if (eq? (vector-ref vec i) item) [(eq? (car l) item) i]
i [else (loop (add1 i) (cdr l))])))
(loop (+ i 1)))]
[else (error 'find-index "didn't find ~e in ~e" item vec)])))
;; open-parents : item -> void ;; open-parents : item -> void
;; selects the item and opens all of its parents. ;; selects the item and opens all of its parents.