slices

package
v1.14.0-snapshot.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedUnique

func SortedUnique[S ~[]T, T constraints.Ordered](s S) S

SortedUnique sorts and dedup the input slice in place. It uses the < operator to compare the elements in the slice and thus requires the elements to satisfies contraints.Ordered.

func SortedUniqueFunc

func SortedUniqueFunc[S ~[]T, T any](
	s S,
	less func(i, j int) bool,
	eq func(a, b T) bool,
) S

SortedUniqueFunc is like SortedUnique but allows the user to specify custom functions for ordering (less function) and comparing (eq function) the elements in the slice. This is useful in all the cases where SortedUnique cannot be used: - for types that do not satisfy constraints.Ordered (e.g: composite types) - when the user wants to customize how elements are compared (e.g: user wants to enforce reverse ordering)

func Unique

func Unique[S ~[]T, T comparable](s S) S

Unique deduplicates the elements in the input slice, preserving their ordering and modifying the slice in place. Unique relies on a map to find multiple occurrences of the same elements. For slices with a size less than 192 elements, a simpler O(N^2) search algorithm that does not allocate memory is used instead. Limit of 192 has been experimentally derived (look at BenchmarkUnique for more information).

Types

This section is empty.

Jump to

Keyboard shortcuts

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