Next: , Previous: , Up: srfi vector spec   [Index]


2.23.4.6 Searching

Function: vector-index pred? vec1 vec2 ... -> exact nonnegative integer or #f

Find and return the index of the first elements in vec1, vec2, … that satisfy pred?. If no matching element is found by the end of the shortest vector, #f is returned.

Examples:

(vector-index even? '#(3 1 4 1 5 9))
=> 2

(vector-index < '#(3 1 4 1 5 9 2 5 6) '#(2 7 1 8 2))
=> 1

(vector-index = '#(3 1 4 1 5 9 2 5 6) '#(2 7 1 8 2))
=> #f
Function: vector-index-right pred? vec1 vec2 ... -> exact nonnegative integer or #f

Like vector-index, but it searches right–to–left, rather than left–to–right, and all of the vectors must have the same length.

Function: vector-skip pred? vec1 vec2 ... -> exact nonnegative integer or #f

Find and return the index of the first elements in vec1, vec2, … that do not satisfy pred?. If all the values in the vectors satisfy pred? until the end of the shortest vector, this returns #f. This is equivalent to:

(vector-index (lambda (x1 x2 ···)
                (not (pred? x1 x1 ···)))
              vec1 vec2 ...)

Example:

(vector-skip number? '#(1 2 a b 3 4 c d))
=> 2
Function: vector-skip-right pred? vec1 vec2 ... -> exact nonnegative integer or #f

Like vector-skip, but it searches for a non–matching element right–to–left, rather than left–to–right, and all of the vectors must have the same length. This is equivalent to:

(vector-index-right (lambda (x1 x2 ...)
                      (not (pred? x1 x1 ...)))
                    vec1 vec2 ...)
Function: vector-binary-search vec value cmp -> exact nonnegative integer or #f

Similar to vector-index and vector-index-right, but instead of searching left to right or right to left, this performs a binary search. cmp should be a procedure of two arguments and return: a negative integer, which indicates that its first argument is less than its second; zero, which indicates that they are equal; a positive integer, which indicates that the first argument is greater than the second argument. An example cmp might be:

(lambda (char1 char2)
  (cond [(char<? char1 char2) -1]
        [(char=? char1 char2) 0]
        [else 1]))
Function: vector-any pred? vec1 vec2 ... -> value or #f

Find the first set of elements in parallel from vec1, vec2, ... for which pred? returns a true value. If such a parallel set of elements exists, vector-any returns the value that pred? returned for that set of elements. The iteration is strictly left–to–right.

Function: vector-every pred? vec1 vec2 ... -> value or #f

If, for every index i between 0 and the length of the shortest vector argument, the set of elements:

(vector-ref vec1 i)
(vector-ref vec2 i)
 ···

satisfies pred?, vector-every returns the value that pred? returned for the last set of elements, at the last index of the shortest vector. The iteration is strictly left–to–right.


Next: , Previous: , Up: srfi vector spec   [Index]