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.
- Source
- Sorting.scala
- Alphabetic
- By Inheritance
- Sorting
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
def
quickSort[K](a: Array[K])(implicit arg0: math.Ordering[K]): Unit
Sort array
a
with quicksort, using the Ordering on its elements.Sort 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. -
def
quickSort(a: Array[Float]): Unit
Sort an array of Floats using
java.util.Arrays.sort
. -
def
quickSort(a: Array[Int]): Unit
Sort an array of Ints using
java.util.Arrays.sort
. -
def
quickSort(a: Array[Double]): Unit
Sort an array of Doubles using
java.util.Arrays.sort
. -
def
stableSort[K, M](a: Seq[K], f: (K) ⇒ M)(implicit arg0: ClassTag[K], arg1: math.Ordering[M]): Array[K]
A sorted Array, given an extraction function
f
that returns an ordered key for each item in the sequencea
.A sorted Array, given an extraction function
f
that returns an ordered key for each item in the sequencea
. Usesjava.util.Arrays.sort
unlessK
is a primitive type. -
def
stableSort[K](a: Seq[K], f: (K, K) ⇒ Boolean)(implicit arg0: ClassTag[K]): Array[K]
A sorted Array, given a function
f
that computes the less-than relation for each item in the sequencea
.A sorted Array, given a function
f
that computes the less-than relation for each item in the sequencea
. Usesjava.util.Arrays.sort
unlessK
is a primitive type. -
def
stableSort[K](a: Seq[K])(implicit arg0: ClassTag[K], arg1: math.Ordering[K]): Array[K]
A sorted Array, using the Ordering for the elements in the sequence
a
.A sorted Array, using the Ordering for the elements in the sequence
a
. Usesjava.util.Arrays.sort
unlessK
is a primitive type. -
def
stableSort[K](a: Array[K], f: (K, K) ⇒ Boolean)(implicit arg0: ClassTag[K]): Unit
Sort array
a
using functionf
that computes the less-than relation for each element.Sort array
a
using functionf
that computes the less-than relation for each element. Usesjava.util.Arrays.sort
unlessK
is a primitive type. -
def
stableSort[K](a: Array[K])(implicit arg0: ClassTag[K], arg1: math.Ordering[K]): Unit
Sort array
a
using the Ordering on its elements, preserving the original ordering where possible.Sort array
a
using the Ordering on its elements, preserving the original ordering where possible. Usesjava.util.Arrays.sort
unlessK
is a primitive type.
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.collection.parallel.immutable
- Immutable, parallel data-structures such asParVector
,ParRange
,ParHashMap
orParHashSet
scala.collection.parallel.mutable
- Mutable, parallel data-structures such asParArray
,ParHashMap
,ParTrieMap
orParHashSet
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect
- Scala's reflection API (scala-reflect.jar)scala.xml
- XML parsing, manipulation, and serialization (scala-xml.jar)scala.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)scala.util.parsing
- Parser combinators (scala-parser-combinators.jar)Automatic imports
Identifiers in the scala package and the
scala.Predef
object are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
List
is an alias forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.