Documentation
¶
Overview ¶
Package sortof provides functions for sorting slices.
Index ¶
- func Bogosort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) error
- func BogosortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) error
- func Miraclesort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) error
- func MiraclesortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) error
- func Slowsort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) error
- func SlowsortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) error
- func Stalinsort[S ~[]E, E cmp.Ordered](ctx context.Context, x S) (S, error)
- func StalinsortFunc[S ~[]E, E any](ctx context.Context, x S, cmp func(a, b E) int) (S, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bogosort ¶
Bogosort sorts the slice x of any ordered type in ascending order. A context controls cancellation, because the worst-case time complexity is O(infinity). When sorting floating-point numbers, NaNs are ordered before other values.
func BogosortFunc ¶
BogosortFunc sorts the slice x of any type in ascending order as determined by the cmp function. A context controls cancellation, because the worst-case time complexity is O(infinity). Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
func Miraclesort ¶ added in v1.2.0
Miraclesort sorts the slice x of any ordered type in ascending order. A context controls cancellation, because miracles are non-deterministic and there is no guarantees, that slice will be ever sorted. When sorting floating-point numbers, NaNs are ordered before other values.
See https://en.wikipedia.org/wiki/Bogosort#Related_algorithms.
func MiraclesortFunc ¶ added in v1.2.0
MiraclesortFunc sorts the slice x of any type in ascending order as determined by the cmp function. A context controls cancellation, because miracles are non-deterministic and there is no guarantees, that slice will be ever sorted. Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
See https://en.wikipedia.org/wiki/Bogosort#Related_algorithms.
func Slowsort ¶
Slowsort sorts the slice x of any ordered type in ascending order. It is practical implementation of multiply and surrender paradigm.
When sorting floating-point numbers, NaNs are ordered before other values. Cancelled context can leave slice partially ordered.
According to algorithm authors, slowsort is most suitable for hourly rated programmers.
See: Andrei Broder and Jorge Stolfi. Pessimal Algorithms and Simplexity Analysis. https://doi.org/10.1145/990534.990536
func SlowsortFunc ¶
SlowsortFunc sorts the slice x of any type in ascending order as determined by the cmp function. Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
Cancelled context can leave slice partially ordered.
See: Andrei Broder and Jorge Stolfi. Pessimal Algorithms and Simplexity Analysis. https://doi.org/10.1145/990534.990536
func Stalinsort ¶
Stalinsort returns slice created from x by deleting elements which are not in ascending order. For compatibility with other functions from package, context controls cancellation.
For floating-point types, a NaN is considered less than any non-NaN, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.
func StalinsortFunc ¶
StalinsortFunc returns slice created from slice x by deleting elements which are not in order determined by the cmp function. For compatibility with other functions from package, context controls cancellation. Function cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
Types ¶
This section is empty.