sort

package module
v0.0.0-...-a0c4baa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2022 License: Unlicense Imports: 3 Imported by: 0

README

Test Go Reference

sort

A faster implementation of Go's sort package for slices.

How

Go now has generics, but the sort implementation uses a lessSwap wrapper struct with the following form:

// lessSwap is a pair of Less and Swap function for use with the
// auto-generated func-optimized variant of sort.go in
// zfuncversion.go.
type lessSwap struct {
	Less func(i, j int) bool
	Swap func(i, j int)
}

Instead of directy operating on slices, swap (data[i], data[j] = data[j], data[i]) and less (data[i] < data[j]) are passed as function literals.

This means each swap, instead of being a quick array access, is a function call then a swap. A similar statement can be made regarding Less. We make this faster be implementing these operations directly on slices, saving us time in the pointer deref and the function call!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LessSort

func LessSort[T any](data []T, less func(a, b *T) bool)

func Ordered

func Ordered[T constraints.Ordered](data []T)

func StructField

func StructField[Struct any, Field constraints.Ordered](base *Struct, field *Field, data []Struct)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL