Documentation ¶
Overview ¶
Package orst is a package that has different sorting methods that can be applied to generic slices or with your own comparator function
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sort ¶
func Sort[T constraints.Ordered](s []T, algorithm Kind, cmp sorter.Comparator[T])
Sort sorts the given slice (by mutating it) with the specified Sorter. If Comparator[T] is nil, sorts in ascending order using the inbuilt comparison operator (<).
Example ¶
slice := []int{3,2,1} // slice = (3,2,1)
with defalt comparator
orst.Sort(slice, orst.BubbleSort, nil) // slice = (1,2,3)
or with custom comparator
orst.Sort(slice, orst.BubbleSort, func(i,j *int) bool { return *j < *i }) // slice = (3,2,1)
func SortAny ¶
func SortAny[T any](s []T, algorithm Kind, cmp sorter.Comparator[T])
Sort sorts the given slice (by mutating it) with the specified Sorter. If Comparator[T] is nil, the function immediately returns without any changes to the slice.
Example ¶
type example struct { val int } slice := []example{{3},{2},{1}} // slice = (3,2,1)
only with custom comparator
orst.SortAny(slice, orst.BubbleSort, func(i,j *example) bool { return i.val < j.val }) // slice = (1,2,3)
Types ¶
Click to show internal directories.
Click to hide internal directories.