sorter

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sort

func Sort[T any](items []T, by func(p1, p2 T) bool)

Sort sorts the argument slice according to the provided "less" function.

Types

type GenericSorter

type GenericSorter[T any] struct {
	Items []T
	By    func(p1, p2 T) bool
}

GenericSorter is a generic sorter for slices of any comparable type.

func (*GenericSorter[T]) Len

func (gs *GenericSorter[T]) Len() int

Len is part of sorter.Interface.

func (*GenericSorter[T]) Less

func (gs *GenericSorter[T]) Less(i, j int) bool

Less is part of sorter.Interface. It calls the "by" closure in the sorter.

func (*GenericSorter[T]) Swap

func (gs *GenericSorter[T]) Swap(i, j int)

Swap is part of sorter.Interface.

Jump to

Keyboard shortcuts

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