Contents

sort(_:sortOrder:)

Sorts a vector of double-precision values in-place.

Declaration

static func sort<V>(_ vector: inout V, sortOrder: vDSP.SortOrder) where V : AccelerateMutableBuffer, V.Element == Double

Parameters

  • vector:

    The array to sort.

  • sortOrder:

    The sort order.

Discussion

The single- and double-precision sort(_:sortOrder:) functions sort an array in place.

The following code sorts an array in ascending order, followed by decending order:

var values: [Float] = [4.0, 8.0, 3.0, 0.0, 7.0, 5.0, 9.0, 2.0, 6.0, 1.0]

vDSP.sort(&values,
          sortOrder: .ascending)

// Prints "[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]".
print(values)

vDSP.sort(&values,
          sortOrder: .descending)

// Prints "[9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0]".
print(values)

See Also

Vector sorting functions