Documentation ¶
Overview ¶
Package sorty is a type-specific, fast, efficient, concurrent/parallel sorting library. It is a QuickSort implementation, is in-place and does not require extra memory. Call corresponding Sort*() to concurrently sort your slices (in ascending order) or collections of objects. For example:
sorty.SortS(string_slice) // native slice sorty.Sort(n, lesswap) // lesswap() function based
Index ¶
- Variables
- func IsSorted(n int, lsw Lesswap) int
- func IsSortedF4(ar []float32) int
- func IsSortedF8(ar []float64) int
- func IsSortedI(ar []int) int
- func IsSortedI4(ar []int32) int
- func IsSortedI8(ar []int64) int
- func IsSortedP(ar []uintptr) int
- func IsSortedS(ar []string) int
- func IsSortedU(ar []uint) int
- func IsSortedU4(ar []uint32) int
- func IsSortedU8(ar []uint64) int
- func Search(n int, fn func(int) bool) int
- func Sort(n int, lsw Lesswap)
- func SortF4(ar []float32)
- func SortF8(ar []float64)
- func SortI(ar []int)
- func SortI4(ar []int32)
- func SortI8(ar []int64)
- func SortP(ar []uintptr)
- func SortS(ar []string)
- func SortU(ar []uint)
- func SortU4(ar []uint32)
- func SortU8(ar []uint64)
- type Lesswap
Constants ¶
This section is empty.
Variables ¶
var ( // Mxg is the maximum concurrent goroutines used for sorting per Sort*() call. Mxg uint32 = 3 // Mli is the maximum array length for insertion sort in // Sort*() except SortS() and Sort(). Mli = 100 // Hmli is the maximum array length for insertion sort in SortS() and Sort(). Hmli = 40 // Mlr is the maximum array length for recursion when there is available goroutines. // So Mlr+1 is the minimum array length for new sorting goroutines. Mlr = 496 )
Functions ¶
func IsSorted ¶
IsSorted returns 0 if underlying collection of length n is sorted, otherwise it returns i > 0 with less(i,i-1) = true.
func IsSortedF4 ¶
IsSortedF4 returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedF8 ¶
IsSortedF8 returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedI ¶
IsSortedI returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedI4 ¶
IsSortedI4 returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedI8 ¶
IsSortedI8 returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedP ¶
IsSortedP returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedS ¶
IsSortedS returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedU ¶
IsSortedU returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedU4 ¶
IsSortedU4 returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func IsSortedU8 ¶
IsSortedU8 returns 0 if ar is sorted in ascending order, otherwise it returns i > 0 with ar[i] < ar[i-1]
func Search ¶
Search returns lowest integer k in [0,n) where fn(k) is true, assuming:
fn(k) => fn(k+1)
If there is no such k, it returns n. It can be used to locate an element in a sorted array or collection.
func Sort ¶
Sort concurrently sorts underlying collection of length n via lsw(). Once for each non-trivial type you want to sort in a certain way, you can implement a custom sorting routine (for a slice for example) as:
func SortObjAsc(c []Obj) { lsw := func(i, k, r, s int) bool { if c[i].Key < c[k].Key { // your custom strict comparator (like < or >) if r != s { c[r], c[s] = c[s], c[r] } return true } return false } sorty.Sort(len(c), lsw) }