Sorting

scala.util.Sorting
object Sorting

The Sorting object provides convenience wrappers for java.util.Arrays.sort. Methods that defer to java.util.Arrays.sort say that they do or under what conditions that they do.

Sorting also implements a general-purpose quicksort and stable (merge) sort for those cases where java.util.Arrays.sort could only be used at the cost of a large memory penalty. If performance rather than memory usage is the primary concern, one may wish to find alternate strategies to use java.util.Arrays.sort directly e.g. by boxing primitives to use a custom ordering on them.

Sorting provides methods where you can provide a comparison function, or can request a sort of items that are scala.math.Ordered or that otherwise have an implicit or explicit scala.math.Ordering.

Note also that high-performance non-default sorts for numeric types are not provided. If this is required, it is advisable to investigate other libraries that cover this use case.

Attributes

Source
Sorting.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Sorting.type

Members list

Value members

Concrete methods

Sorts an array of Doubles using java.util.Arrays.sort.

Sorts an array of Doubles using java.util.Arrays.sort.

Value parameters

a

the array of Doubles to sort in place

Attributes

Source
Sorting.scala
def quickSort(a: Array[Int]): Unit

Sorts an array of Ints using java.util.Arrays.sort.

Sorts an array of Ints using java.util.Arrays.sort.

Value parameters

a

the array of Ints to sort in place

Attributes

Source
Sorting.scala

Sorts an array of Floats using java.util.Arrays.sort.

Sorts an array of Floats using java.util.Arrays.sort.

Value parameters

a

the array of Floats to sort in place

Attributes

Source
Sorting.scala
def quickSort[K : Ordering](a: Array[K]): Unit

Sorts array a with quicksort, using the Ordering on its elements. This algorithm sorts in place, so no additional memory is used aside from what might be required to box individual elements during comparison.

Sorts array a with quicksort, using the Ordering on its elements. This algorithm sorts in place, so no additional memory is used aside from what might be required to box individual elements during comparison.

Type parameters

K

the element type of the array, which must have an Ordering

Value parameters

a

the array to sort in place

Attributes

Source
Sorting.scala
def stableSort[K : Ordering](a: Array[K]): Unit

Sorts array a using the Ordering on its elements, preserving the original ordering where possible. Uses java.util.Arrays.sort unless K is a primitive type. This is the same as stableSort(a, 0, a.length).

Sorts array a using the Ordering on its elements, preserving the original ordering where possible. Uses java.util.Arrays.sort unless K is a primitive type. This is the same as stableSort(a, 0, a.length).

Type parameters

K

the element type of the array, which must have an Ordering

Value parameters

a

the array to sort in place

Attributes

Source
Sorting.scala
def stableSort[K : Ordering](a: Array[K], from: Int, until: Int): Unit

Sorts array a or a part of it using the Ordering on its elements, preserving the original ordering where possible. Uses java.util.Arrays.sort unless K is a primitive type.

Sorts array a or a part of it using the Ordering on its elements, preserving the original ordering where possible. Uses java.util.Arrays.sort unless K is a primitive type.

Type parameters

K

the element type of the array, which must have an Ordering

Value parameters

a

the array to sort in place

from

the first index in the array to sort

until

the last index (exclusive) in the array to sort

Attributes

Source
Sorting.scala
def stableSort[K](a: Array[K], f: (K, K) => Boolean): Unit

Sorts array a using function f that computes the less-than relation for each element. Uses java.util.Arrays.sort unless K is a primitive type. This is the same as stableSort(a, f, 0, a.length).

Sorts array a using function f that computes the less-than relation for each element. Uses java.util.Arrays.sort unless K is a primitive type. This is the same as stableSort(a, f, 0, a.length).

Type parameters

K

the element type of the array

Value parameters

a

the array to sort in place

f

a function that returns true if its first argument is less than its second

Attributes

Source
Sorting.scala
def stableSort[K](a: Array[K], f: (K, K) => Boolean, from: Int, until: Int): Unit

Sorts array a or a part of it using function f that computes the less-than relation for each element. Uses java.util.Arrays.sort unless K is a primitive type.

Sorts array a or a part of it using function f that computes the less-than relation for each element. Uses java.util.Arrays.sort unless K is a primitive type.

Type parameters

K

the element type of the array

Value parameters

a

the array to sort in place

f

a function that returns true if its first argument is less than its second

from

the first index in the array to sort

until

the last index (exclusive) in the array to sort

Attributes

Source
Sorting.scala
def stableSort[K : ClassTag : Ordering](a: Seq[K]): Array[K]

A sorted Array, using the Ordering for the elements in the sequence a. Uses java.util.Arrays.sort unless K is a primitive type.

A sorted Array, using the Ordering for the elements in the sequence a. Uses java.util.Arrays.sort unless K is a primitive type.

Type parameters

K

the element type, which must have a ClassTag and an Ordering

Value parameters

a

the sequence of elements to sort

Attributes

Source
Sorting.scala
def stableSort[K : ClassTag](a: Seq[K], f: (K, K) => Boolean): Array[K]

A sorted Array, given a function f that computes the less-than relation for each item in the sequence a. Uses java.util.Arrays.sort unless K is a primitive type.

A sorted Array, given a function f that computes the less-than relation for each item in the sequence a. Uses java.util.Arrays.sort unless K is a primitive type.

Type parameters

K

the element type, which must have a ClassTag

Value parameters

a

the sequence of elements to sort

f

a function that returns true if its first argument is less than its second

Attributes

Source
Sorting.scala
def stableSort[K : ClassTag, M : Ordering](a: Seq[K], f: K => M): Array[K]

A sorted Array, given an extraction function f that returns an ordered key for each item in the sequence a. Uses java.util.Arrays.sort unless K is a primitive type.

A sorted Array, given an extraction function f that returns an ordered key for each item in the sequence a. Uses java.util.Arrays.sort unless K is a primitive type.

Type parameters

K

the element type, which must have a ClassTag

M

the key type returned by the extraction function, which must have an Ordering

Value parameters

a

the sequence of elements to sort

f

a function that extracts a comparable key from each element

Attributes

Source
Sorting.scala