Documentation ¶
Overview ¶
Package sort is a package for sorting data.
Index ¶
- Constants
- func Bubble[T constraints.Ordered](data Slice[T], direction direction)
- func BubbleStruct[T constraints.Ordered, V Element[T]](data Elements[T, V], direction direction)
- func Insertion[T constraints.Ordered](data Slice[T], direction direction)
- func InsertionStruct[T constraints.Ordered, V Element[T]](data Elements[T, V], direction direction)
- func Quick[T constraints.Ordered](data Slice[T], direction direction)
- func QuickStruct[T constraints.Ordered, V Element[T]](data Elements[T, V], direction direction)
- type Element
- type Elements
- type Person
- type Slice
Constants ¶
View Source
const ( // Desc specifies the sort direction to be descending. Desc direction = "desc" // Asc specifies the sort direction to be ascending. Asc direction = "asc" )
Variables ¶
This section is empty.
Functions ¶
func Bubble ¶
func Bubble[T constraints.Ordered](data Slice[T], direction direction)
Bubble sorts data using bubble sort algorithm
- first param is a slice of constraints.Ordered elements (string, int, float64...)
- second param should be `type direction` (`sort.Asc` or `sort.Desc`)
func BubbleStruct ¶
func BubbleStruct[T constraints.Ordered, V Element[T]](data Elements[T, V], direction direction)
BubbleStruct sorts data of structures using bubble sort algorithm
- first param is a slice of structure elements. This slice should implement Element interface
- second param should be `type direction` (`sort.Asc` or `sort.Desc`)
func Insertion ¶
func Insertion[T constraints.Ordered](data Slice[T], direction direction)
Insertion sorts data using insertion sort algorithm
- first param is a slice of constraints.Ordered elements (string, int, float64...)
- second param should be `type direction` (`sort.Asc` or `sort.Desc`)
func InsertionStruct ¶
func InsertionStruct[T constraints.Ordered, V Element[T]](data Elements[T, V], direction direction)
InsertionStruct sorts data of structures using insertion sort algorithm
- first param is a slice of structure elements. This slice should implement Element interface
- second param should be `type direction` (`sort.Asc` or `sort.Desc`)
func Quick ¶ added in v1.1.0
func Quick[T constraints.Ordered](data Slice[T], direction direction)
func QuickStruct ¶ added in v1.1.0
func QuickStruct[T constraints.Ordered, V Element[T]](data Elements[T, V], direction direction)
Types ¶
type Element ¶
type Element[V constraints.Ordered] interface { // Element returns value of element. // Type of this element should be constraints.Ordered (int, string, float64 etc) // This function will be used for comparing elements Element() V }
Element is an interface which needs to implement for slice sorting
type Elements ¶
type Elements[T constraints.Ordered, V Element[T]] []V
Click to show internal directories.
Click to hide internal directories.