Previous: Cutting Vectors, Up: Vectors


8.4 Modifying Vectors

— procedure: vector-fill! vector object
— procedure: subvector-fill! vector start end object

Stores object in every element of the vector (subvector) and returns an unspecified value.

— procedure: subvector-move-left! vector1 start1 end1 vector2 start2
— procedure: subvector-move-right! vector1 start1 end1 vector2 start2

Destructively copies the elements of vector1, starting with index start1 (inclusive) and ending with end1 (exclusive), into vector2 starting at index start2 (inclusive). Vector1, start1, and end1 must specify a valid subvector, and start2 must be a valid index for vector2. The length of the source subvector must not exceed the length of vector2 minus the index start2.

The elements are copied as follows (note that this is only important when vector1 and vector2 are eqv?):

subvector-move-left!
The copy starts at the left end and moves toward the right (from smaller indices to larger). Thus if vector1 and vector2 are the same, this procedure moves the elements toward the left inside the vector.
subvector-move-right!
The copy starts at the right end and moves toward the left (from larger indices to smaller). Thus if vector1 and vector2 are the same, this procedure moves the elements toward the right inside the vector.

— procedure: sort! vector procedure
— procedure: merge-sort! vector procedure
— procedure: quick-sort! vector procedure

Procedure must be a procedure of two arguments that defines a total ordering on the elements of vector. The elements of vector are rearranged so that they are sorted in the order defined by procedure. The elements are rearranged in place, that is, vector is destructively modified so that its elements are in the new order.

sort! returns vector as its value.

Two sorting algorithms are implemented: merge-sort! and quick-sort!. The procedure sort! is an alias for merge-sort!.

See also the definition of sort.