;; data/core/vector-lib.scm - vector procedures
;;
;; Copyright (C) 2000 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
;;
;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; 
;; This software is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;; 
;; You should have received a copy of the GNU General Public License
;; along with this package; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.  

(define-module (core vector-lib))

(export vector-tabulate vector-copy vector=)

(define (vector-tabulate count init-proc)
  (let ((vec (make-vector count)))
    (do ((idx 0 (+ idx 1)))
	((>= idx count) vec)
      (vector-set! vec idx (init-proc idx)))))

(define (vector-copy vec)
  (vector-tabulate (vector-length vec)
		   (lambda (n) (vector-ref vec n))))

(define (vector= elt= vec1 . vecs)
  (let ((vec1-length (vector-length vec1)))
    (let lp0 ((vecs vecs))
      (if (not-pair? vecs)
	  #t
	  (let ((vec2 (car vecs)))
	    (if (= vec1-length (vector-length vec2))
		(let lp ((idx 0))
		  (if (>= idx vec1-length)
		      (lp0 (cdr vecs))
		      (if (elt= (vector-ref vec1 idx) (vector-ref vec2 idx))
			  (lp (+ idx 1))
			  #f)))
		#f))))))
