Documentation ¶
Overview ¶
Package zermelo is a library for sorting slices in Go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sort ¶
Sort attempts to sort x.
If x is a supported slice type, this library will be used to sort it. Otherwise, if x implements sort.Interface it will passthrough to the sort.Sort() algorithm. Returns an error on unsupported types. As of v1.5.0, is generally preferable to use zermelo.SortIntegers or zermelo.SortFloats instead.
func SortFloats ¶ added in v1.5.0
func SortFloats[F constraints.Float](x []F)
SortFloats sorts float slices. If the slice is large enough, radix sort is used by allocating a new buffer.
func SortFloatsBYOB ¶ added in v1.5.0
func SortFloatsBYOB[F constraints.Float](x, buffer []F)
SortFloatsBYOB sorts float slices with radix sort using the provided buffer. len(buffer) must be greater or equal to len(x).
func SortIntegers ¶ added in v1.5.0
func SortIntegers[T constraints.Integer](x []T)
SortIntegers sorts integer slices. If the slice is large enough, radix sort is used by allocating a new buffer.
func SortIntegersBYOB ¶ added in v1.5.0
func SortIntegersBYOB[T constraints.Integer](x, buffer []T)
SortIntegersBYOB sorts integer slices with radix sort using the provided buffer. len(buf) must be greater or equal to len(x).
Types ¶
type FloatSorter ¶ added in v1.5.0
type FloatSorter[F constraints.Float] interface { // Sort sorts float slices Sort(x []F) }
FloatSorter describes types that can sort float slices
func NewFloatSorter ¶ added in v1.5.0
func NewFloatSorter[F constraints.Float]() FloatSorter[F]
NewFloatSorter creates a new FloatSorter that will use radix sort on large slices and reuses buffers. The first sort creates a buffer the same size as the slice being sorted and keeps it for future use. Later sorts may grow this buffer as needed. The FloatSorter returned is not thread safe. Using this sorter can be much faster than repeat calls to SortFloats.
type IntSorter ¶ added in v1.5.0
type IntSorter[I constraints.Integer] interface { // Sort sorts integer slices. Sort(x []I) }
IntSorter describes types that can sort integer slices
func NewIntSorter ¶ added in v1.5.0
func NewIntSorter[I constraints.Integer]() IntSorter[I]
NewIntSorter creates a new IntSorter that will use radix sort on large slices and reuses buffers. The first sort creates a buffer the same size as the slice being sorted and keeps it for future use. Later sorts may grow this buffer as needed. The IntSorter returned is not thread safe. Using this sorter can be much faster than repeat calls to SortIntegers.
type Sorter ¶
type Sorter interface { // Sort attempts to sort x, returning an error if unable to sort. Sort(x any) error // CopySort returns a sorted copy of x, or an error if unable to copy or sort. CopySort(x any) (any, error) }
Sorter can sort slices. This interface is deprecated, use IntSorter or FloatSorter.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package zfloat32 implements radix sort for []float32.
|
Package zfloat32 implements radix sort for []float32. |
Package zfloat64 implements radix sort for []float64.
|
Package zfloat64 implements radix sort for []float64. |
Package zint implements radix sort for []int.
|
Package zint implements radix sort for []int. |
Package zint32 implements radix sort for []int32.
|
Package zint32 implements radix sort for []int32. |
Package zint64 implements radix sort for []int64.
|
Package zint64 implements radix sort for []int64. |
Package zuint implements radix sort for []uint.
|
Package zuint implements radix sort for []uint. |
Package zuint32 implements radix sort for []uint32.
|
Package zuint32 implements radix sort for []uint32. |
Package zuint64 implements radix sort for []uint64.
|
Package zuint64 implements radix sort for []uint64. |