floats

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 5 Imported by: 0

README

zermelo/floats

This subpackage handles sorting float slices.

Example

package main

import (
	"github.com/shawnsmithdev/zermelo/v2/floats"
	"something"
)

func main() {
	var x []float64
	x = something.GetFloatData()
	floats.SortFloats(x)
}

Sorter

The Sorter returned by NewFloatSorter() will reuse buffers created during Sort() calls. This is not thread safe, and behaves in the same manner as zermelo.NewSorter(), but for float types.

Sorter Example

package main

import (
	"github.com/shawnsmithdev/zermelo/v2/floats"
	"something"
)

func main() {
	var x [][]float64
	x = something.GetFloatDatas()
	sorter := floats.NewFloatSorter[float64]()
	for _, y := range x {
		sorter.Sort(y)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFloatSorter

func NewFloatSorter[F Float]() zermelo.Sorter[F]

NewFloatSorter creates a new Sorter for float slices 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.

func SortFloats

func SortFloats[F Float](x []F)

SortFloats sorts float slices. If the slice is large enough, radix sort is used by allocating a new buffer.

func SortFloatsBYOB

func SortFloatsBYOB[F 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).

Types

type Float added in v2.1.0

type Float interface {
	~float32 | ~float64
}

Float is a constraint that permits any floating-point type.

Jump to

Keyboard shortcuts

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