quick

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT-0 Imports: 1 Imported by: 2

Documentation

Overview

Package quick implements Tony Hoare's Quicksort and Quickselect.

This package avoids quadratic behavior by using median-of-ninthers when a bad pivot is detected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Select

func Select[T cmp.Ordered](s []T, k int) T

Select uses the Quickselect algorithm to find element k of the slice, partially sorting the slice around, and returning, s[k]. It uses O(n) time and O(log₉(n)) space.

func Sort

func Sort[T cmp.Ordered](s []T)

Sort uses the Quicksort algorithm to sort a slice. It uses O(n·log(n)) time and O(log(n)) space.

func SortFirst

func SortFirst[T cmp.Ordered](s []T, k int)

SortFirst uses the Quickselect and Quicksort algorithms to sort the first k elements of a slice. It uses O(n + k·log(k)) time and O(log(n)) space.

func SortLast added in v0.1.3

func SortLast[T cmp.Ordered](s []T, k int)

SortLast uses the Quickselect and Quicksort algorithms to sort the last k elements of a slice. It uses O(n + k·log(k)) time and O(log(n)) space.

Types

This section is empty.

Jump to

Keyboard shortcuts

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