[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.14 srfi-43 - ベクタライブラリ

Module: srfi-43

このモジュールはベクタ用のライブラリ関数を提供します。 SRFI-43のいくつかの関数は組み込みになっています。ベクタを見てく ださい。

ベクタ構成子

Function: vector-unfold f length seed …

[SRFI-43]

Function: vector-unfold-right f length seed …

[SRFI-43]

Function: vector-reverse-copy vec :optional start end

[SRFI-43]

Function: vector-append vec …

[SRFI-43] Returns a newly allocated vector whose contents are concatenation of elements of vec in order.

Function: vector-concatenate list-of-vectors

[SRFI-43] Acts like (apply vector-append list-of-vectors), though this may be more efficient.

ベクタ上の述語

Function: vector-empty? vec

[SRFI-43] Returns #t if vec’s length is zero, and #f if vec’s length is more than zero. Signals an error if vec is not a vector.

Function: vector= elt= vec …

[SRFI-43] Compares vecs element-wise, using given predicate elt=. Returns #t iff lengths of all the vectors are the same, and every corresponding elements are equal by elt=. Elt= is always called with two arguments and must return #t iff two are the same.

ベクタ上の反復

Function: vector-fold kons knil vec1 vec2 …

[SRFI-43] Kons is a procedure that takes n+2 arguments, where n is the number of given vectors. For each element of the given vectors, kons is called as (kons i seed e_1i e_2i …), where i is the index, and e_ni is the i-th element of the vector n. If the lengths of the vectors differ, iteration stops when the shortest vector is exhausted.

The initial value of seed is knil, and the return value from kons is used as the next seed value. The last return value of kons is returned from vector-fold.

The iteration is strictly left to right.

Note that the seed value precedes elements, which is opposite to fold (See section コレクションに対するマッピング). It’s an unfortunate historical glitch; vector-fold-left would be more consistent name.

Function: vector-fold-right kons knil vec1 vec2 …

[SRFI-43] Like vector-fold, but iterates right to left.

Function: vector-map f vec1 vec2 …
Function: vector-map! f vec1 vec2 …
Function: vector-for-each f vec1 vec2 …
Function: vector-count f vec1 vec2 …

[SRFI-43] The argument f is a procedure that takes n+1 arguments where n is the number of given vectors. These procedures call f for each element of the given vectors as (f i e_1i e_2i …), where i is the index, and e_ni is the i-th element of the vector n. If the lengths of the vectors differ, iteration only covers the shortest vector.

vector-map creates a fresh vector out of the result of applications of f and returns it. vector-map! reuses vec1 to store the result and returns vec1; hence vec1 must be mutable.

vector-for-each is for side-effects. It discards the result of f.

vector-count counts the number of times f returned a true value.

 
(vector-map list '#(a b c))
 ⇒ #((0 a) (1 b) (2 c))
(vector-map list '#(a b c) '#(d e f g))
 ⇒ #((0 a d) (1 b e) (2 c f))
(vector-count = '#(0 2 2 4 4))
 ⇒ 3

Note: The generic map and for-each in gauche.collection can be used on vectors, but the procedure is called without index, and the result is returned as a list. (vector-map f vec1 vec2 …) is operationally equivalent to (map-to-with-index <vector> f vec1 vec2 …). See gauche.collection - コレクションフレームワーク and gauche.sequence - シーケンスフレームワーク.

ベクタ上の検索

Function: vector-index pred vec1 vec2 …
Function: vector-index-right pred vec1 vec2 …

[SRFI-43] Returns the index of the first or the last elements in vec1 vec2 … that satisfy pred, respectively. Returns #f if no elements satisfy pred. In vector-index, comparison ends at the end of the shortest vector. For vector-index-right, all the vectors must have the same length.

Function: vector-skip pred vec1 vec2 …
Function: vector-skip-right pred vec1 vec2 …

[SRFI-43] Like vector-index and vector-index-right, except that the result of pred is negated. That is, returns the index of the first or the last elements that don’t sastisfy pred.

Function: vector-binary-search vec value cmp :optional start end

[SRFI-43+] Look for value in a vector vec, and returns its index if it is found, or #f if it is not found. Comparison of value and an element in vec is done by a procedure cmp, which takes two arguments, and should return a negative integer if the first argument is less than the second, 0 if they are the same, and a positive integer if the first is greater than tne second.

Elements in vec must be ordered from smaller to greater w.r.t. cmp. Using that fact, this procedure performs binary search instead of linear search.

The optional arguments start and end are an extention to SRFI-43, and can be used to limit the range of the search in start-th element (inclusive) to end-th element (exclusive).

Function: vector-any pred vec1 vec2 …

[SRFI-43] Applies pred on each corresponding elements of vec1 vec2 … left to right, and as soon as pred returns non-#f value, the procedure stops iteration and returns the value.

If no elements that satisfy pred are found, it returns #f.

Vectors can have different lengths. Iteration stops at the end of the shortest.

Function: vector-every pred vec1 vec2 …

[SRFI-43] Applies pred on each corresponding elements of vec1 vec2 … left to right. If all the elements (when the lengths of vectors differ, the first N elements where N is the length of the shortest) satisfy pred, returns the last result of pred. Otherwise returns #t.

ベクタの変更子

Function: vector-swap! vec i j

[SRFI-43] Swaps vector vec’s i-th and j-th elements.

Function: vector-reverse! vec :optional start end

[SRFI-43]

Function: vector-copy! target tstart source :optional sstart send

[SRFI-43]

Function: vector-reverse-copy! target tstart source :optional sstart send

[SRFI-43]

ベクタの変換

Function: reverse-vector->list vec :optional start end

[SRFI-43]

Function: reverse-list->vector list :optional start end

[SRFI-43]


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Shiro Kawai on May 28, 2012 using texi2html 1.82.