mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
fast-path vector-map on two vectors
This commit is contained in:
parent
49072ebbf4
commit
3716d99a02
1 changed files with 13 additions and 3 deletions
|
@ -187,12 +187,22 @@
|
|||
(lp (cdr ls) (+ i v-len)))))))
|
||||
|
||||
(define (vector-map proc vec . lov)
|
||||
(if (null? lov)
|
||||
(cond
|
||||
((null? lov)
|
||||
(let lp ((i (vector-length vec)) (res '()))
|
||||
(if (zero? i)
|
||||
(list->vector res)
|
||||
(lp (- i 1) (cons (proc (vector-ref vec (- i 1))) res)))))
|
||||
((null? (cdr lov))
|
||||
(let ((vec2 (car lov)))
|
||||
(let lp ((i (vector-length vec)) (res '()))
|
||||
(if (zero? i)
|
||||
(list->vector res)
|
||||
(lp (- i 1) (cons (proc (vector-ref vec (- i 1))) res))))
|
||||
(list->vector (apply map proc (map vector->list (cons vec lov))))))
|
||||
(lp (- i 1)
|
||||
(cons (proc (vector-ref vec (- i 1)) (vector-ref vec2 (- i 1)))
|
||||
res))))))
|
||||
(else
|
||||
(list->vector (apply map proc (map vector->list (cons vec lov)))))))
|
||||
|
||||
(define (vector-for-each proc vec . lov)
|
||||
(if (null? lov)
|
||||
|
|
Loading…
Add table
Reference in a new issue