sorters

package
v0.0.2-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sorter

type Sorter[T any] interface {
	Sort(arr *[]T)
	SortP(arr *[]*T)
}

func Binary

func Binary[T any](comparator comparables.Comparator[T]) Sorter[T]

func Get

func Get[T Sorter[S], S prim.Ordered]() Sorter[S]

Get returns a new instance of the Sorter interface using the default comparator.

The implementation will depend on the type parameter T. If T is a mergeSorter, Quick or binarySorter, the respective Sorter instance will be returned. Otherwise, the Native Sorter will be returned.

Note: The default comparator is an instance of comparables.Ordered[S]{}, which is the default comparator for the given type S.

func Merge

func Merge[T prim.Ordered](comparator comparables.Comparator[T]) Sorter[T]

func Native

func Native[T any](comparator comparables.Comparator[T]) Sorter[T]

Native returns a Sorter that uses the native sort function from the standard library.

func Quick

func Quick[T any](comparator comparables.Comparator[T]) Sorter[T]

Quick creates a new instance of Sorter that uses the quickSorter with the given comparator. The comparator is used to compare elements in the array during the sorting process.

Parameters: - comparator: A function that takes two elements of type T and returns a boolean indicating their order.

Returns: - *quickSorter[T]: A pointer to the newly created quickSorter struct.

Jump to

Keyboard shortcuts

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