vector-sort! - (possibly unstable) sorting of vectors
(import (rnrs)) ;R6RS
(import (rnrs sorting)) ;R6RS
(vector-sort! proc vector)
Destructively sorts vector in ascending order according to proc.
The procedure proc should accept two elements and return a true value
when its first argument is strictly less than its second, and #f
otherwise.
The sorting algorithm may be unstable. This means that two
elements which are equal according to proc but not according to
eq?(3scm) may change order.
- Time complexity
- The sorting algorithm performs O(n²) calls to proc where n
is the length of vector.
- Unspecified order and side effects
- The pairing of arguments and the sequencing of calls to proc are
not specified. The procedure proc should not have any side
effects.
Most practical sorting algorithms may be used, with Quicksort and merge sort
being common choices.
This procedure returns unspecified values.
(define v (vector 3 5 2 1))
(vector-sort! < v) => unspecified
v => #(1 2 3 5)
The requirements placed on this procedure are less strict so that simple
in-place algorithms like Quicksort can be used.
These procedures are unique to R6RS. Alternatives are available in SRFI-95 and
SRFI-132.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its
domain. In particular, proc should accept two arguments, which are
elements from list or vector, and return one value.
This procedure first appeared in R6RS.