class Sorting[T] extends AnyRef
The Sorting
class provides direct and indirect methods to:
find 'k'-th median ('k'-th smallest element) using QuickSelect
sort large arrays using QuickSort
sort large arrays using MergeSort
(slower than quicksort, but stable)
sort small arrays using SelectionSort
Direct methods are faster, but modify the array, while indirect methods are slower, but do not modify the array. This class is generic.
- See also
SortingC
for a version of this class specialized forComplex
.SortingD
for a version of this class specialized forDouble
.SortingI
for a version of this class specialized forInt
.SortingL
for a version of this class specialized forLong
.SortingQ
for a version of this class specialized forRational
.SortingR
for a version of this class specialized forReal
.SortingS
for a version of this class specialized forStrNum
.
- Alphabetic
- By Inheritance
- Sorting
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Sorting(a: Array[T])(implicit arg0: ClassTag[T], ev: (T) => Ordered[T])
- a
the array to operate on
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def imedian(k: Int = (n+1)/2): T
Indirectly find the 'k'-median ('k'-th smallest element) of array 'a'.
Indirectly find the 'k'-median ('k'-th smallest element) of array 'a'.
- k
the type of median (e.g., k = (n+1)/2 is the median)
- def iqsort(): Array[Int]
Indirectly sort array 'a' using
QuickSort
, returning the rank order. - final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isSorted(rk: Array[Int]): Boolean
Determine whether the array 'a' is indirectly sorted.
Determine whether the array 'a' is indirectly sorted.
- rk
the rank order
- def isSorted: Boolean
Determine whether the array 'a' is sorted.
- def iselsort(k: Int, asc: Boolean = true): Array[Int]
Partially, indirectly sort array 'a' using
SelectionSort
returning the first/smallest 'k' elements.Partially, indirectly sort array 'a' using
SelectionSort
returning the first/smallest 'k' elements. Can be used for top-k (smallest) or bottom-k (largest) selection.- k
the number of elements to sort and return
- asc
whether to sort in ascending (true) or descending (false) order
- def iselsort(): Array[Int]
Indirectly sort array 'a' using
SelectionSort
, returning the rank order. - final def med3(i: Int, j: Int, k: Int): Int
Return the index of the median of three elements.
Return the index of the median of three elements.
- i
element index 1
- j
element index 2
- k
element index 3
- Annotations
- @inline()
- See also
Sorting
companion object for 'median3' function
- def median(rk: Array[Int], p: Int, r: Int, k: Int): T
Indirectly find the 'k'-median of the 'p' to 'r' partition of array 'a' using the
QuickSelect
algorithm.Indirectly find the 'k'-median of the 'p' to 'r' partition of array 'a' using the
QuickSelect
algorithm.- rk
the rank order
- p
the left cursor
- r
the right cursor
- k
the type of median (k-th smallest element)
- See also
http://en.wikipedia.org/wiki/Quickselect
- def median(k: Int = (n+1) / 2): T
Find the 'k'-median ('k'-th smallest element) of array 'a'.
Find the 'k'-median ('k'-th smallest element) of array 'a'.
- k
the type of median (e.g., 'k = (n+1) / 2' is the median)
- def median(p: Int, r: Int, k: Int): T
Find the 'k'-median of the 'p' to 'r' partition of array 'a' using the
QuickSelect
algorithm.Find the 'k'-median of the 'p' to 'r' partition of array 'a' using the
QuickSelect
algorithm.- p
the left cursor
- r
the right cursor
- k
the type of median (k-th smallest element)
- See also
en.wikipedia.org/wiki/Quickselect
- def merge(x: Array[T], ii: Int, jj: Int, kk: Int, y: Array[T]): Unit
Merge sorted runs of one array into another.
Merge sorted runs of one array into another. Examaple: merge | 1, 3 | with | 2, 4 | to get | 1, 2, 3, 4 |. Run 1: x(ii until jj) Run 2: x(jj until kk)
- x
the source (from) array
- ii
the start of first run
- jj
the start of second run
- kk
the end (exclusive) of second run
- y
the destination (to) array
- def msort(): Unit
Sort array 'a' using
MergeSort
(stable sorting algorithm).Sort array 'a' using
MergeSort
(stable sorting algorithm). Uses a bottom-up approach.- See also
https://en.wikipedia.org/wiki/Merge_sort
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def partition(rk: Array[Int], p: Int, r: Int): Int
Indirectly partition the array from 'p' to 'r' into a left partition (<= 'x') and a right partition (>= 'x').
Indirectly partition the array from 'p' to 'r' into a left partition (<= 'x') and a right partition (>= 'x').
- rk
the rank order
- p
the left cursor
- r
the right cursor
- def partition(p: Int, r: Int): Int
Partition the array from 'p' to 'q' into a left partition (<= 'x') and a right partition (>= 'x').
Partition the array from 'p' to 'q' into a left partition (<= 'x') and a right partition (>= 'x').
- p
the left cursor
- def qsort(rk: Array[Int], p: Int, r: Int): Unit
Recursively and indirectly sort the 'p' to 'r' partition of array 'a' using
QuickSort
.Recursively and indirectly sort the 'p' to 'r' partition of array 'a' using
QuickSort
.- rk
the rank order
- p
the left cursor
- r
the right cursor
- def qsort(): Unit
Sort array 'a' using
QuickSort
(unstable sorting algorithm). - def qsort(p: Int, r: Int): Unit
Recursively sort the 'p' to 'r' partition of array 'a' using
QuickSort
.Recursively sort the 'p' to 'r' partition of array 'a' using
QuickSort
.- p
the left cursor
- r
the right cursor
- See also
http://mitpress.mit.edu/books/introduction-algorithms
- def selsort(rk: Array[Int], p: Int, r: Int): Unit
Indirectly sort the 'p' to 'r' partition of array 'a' using
SelectionSort
.Indirectly sort the 'p' to 'r' partition of array 'a' using
SelectionSort
.- rk
the rank order
- p
the left cursor
- r
the right cursor
- def selsort(k: Int, asc: Boolean = true): Array[T]
Partially sort array 'a' using
SelectionSort
returning the first/smallest 'k' elements.Partially sort array 'a' using
SelectionSort
returning the first/smallest 'k' elements. Can be used for top-k (smallest) or bottom-k (largest) selection.- k
the number of elements to sort and return
- asc
whether to sort in ascending (true) or descending (false) order
- def selsort(): Unit
Sort array 'a' using
SelectionSort
. - def selsort(p: Int, r: Int): Unit
Sort the 'p' to 'r' partition of array 'a' using
SelectionSort
.Sort the 'p' to 'r' partition of array 'a' using
SelectionSort
.- p
the left cursor
- r
the right cursor
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def top(k: Int): Array[T]
Return the smallest 'k' elements (top-k) of array 'a'.
Return the smallest 'k' elements (top-k) of array 'a'.
- k
the number of samllest elements to return
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated