Help us shape the future of Go! Take the 2026 Go Developer Survey

sort

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sort provides SIMD-accelerated sorting for the dataset engines.

Sort dispatches to the best available algorithm per type:

  • RadixSort for integers and floats (O(n), SIMD-accelerated)
  • VQSort as comparison-based fallback (vectorized quicksort)
  • Sorting networks for very small arrays (≤32 elements)

NthElement provides O(n) partial sorting for computing quantiles (Median, percentiles) without a full sort.

Architecture dispatch is automatic:

AMD64: AVX-512 → AVX2 → scalar
ARM64: NEON → scalar
Other: pure Go fallback

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndicesFloat64 added in v0.0.2

func IndicesFloat64(data []float64) []int

IndicesFloat64 returns the indices that would sort the data. Uses Go's stdlib pdqsort (slices.SortFunc) on (value, index) pairs.

func IndicesInt64 added in v0.0.2

func IndicesInt64(data []int64) []int

IndicesInt64 returns the indices that would sort the data.

func IndicesString added in v0.0.2

func IndicesString(data []string) []int

IndicesString returns the indices that would sort the data.

func NthElement

func NthElement[T hwy.Lanes](data []T, k int)

NthElement rearranges data such that data[k] is the element that would be at position k if data were fully sorted. Elements before k are ≤ data[k], elements after are ≥ data[k]. Average O(n).

This is the core primitive for Median and quantile computation:

NthElement(data, n/2)  // data[n/2] is now the median

func Small added in v0.0.2

func Small[T hwy.Lanes](data []T)

Small sorts data of length ≤32 using a SIMD sorting network. For larger data, use Sort instead.

func Sort

func Sort[T hwy.Lanes](data []T)

Sort sorts data in-place using the best algorithm for the type. Uses SIMD RadixSort (O(n)) for integers and floats.

func VQSort

func VQSort[T hwy.Lanes](data []T)

VQSort sorts data in-place using vectorized quicksort. O(n log n) comparison-based with SIMD-accelerated partitioning.

Types

This section is empty.

Jump to

Keyboard shortcuts

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