sliceutils

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package sliceutils provides types and functions for various operations over sliceutils of different types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReverseHeap

func ReverseHeap(data heap.Interface) heap.Interface

ReverseHeap returns the reverse order for data.

Types

type IndexedSlice

type IndexedSlice[T Ordered] struct {
	// Slice of values exposed to the sorting operation.
	Slice []T
	// Indices is initialized with the index of each element
	// in the original slice, and is sorted in parallel with Slice.
	Indices []int
}

IndexedSlice allows sorting a slice of Ordered values without losing track of the initial (pre-sorting) index of each element.

func NewIndexedSlice

func NewIndexedSlice[T Ordered](slice []T) IndexedSlice[T]

NewIndexedSlice creates a new IndexedSlice.

func (IndexedSlice[_]) Len

func (s IndexedSlice[_]) Len() int

Len returns the length of the slice.

func (IndexedSlice[T]) Less

func (s IndexedSlice[T]) Less(i, j int) bool

Less reports whether the value at index i is less than the value at index j.

func (IndexedSlice[T]) Swap

func (s IndexedSlice[T]) Swap(i, j int)

Swap swaps the elements at indices i and j, on both Indices and Slice.

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 |
		~string
}

Ordered is a type constraint that permits any ordered type, that is, any type supporting the operators < <= >= >.

type OrderedHeap

type OrderedHeap[T Ordered] []T

OrderedHeap is a min-heap of Ordered values.

func (OrderedHeap[_]) Len

func (t OrderedHeap[_]) Len() int

Len returns the length of the heap.

func (OrderedHeap[_]) Less

func (t OrderedHeap[_]) Less(i, j int) bool

Less reports whether the value at index i is less than the value at index j.

func (*OrderedHeap[T]) Pop

func (t *OrderedHeap[T]) Pop() any

Pop removes the last element from the heap and returns its value.

func (*OrderedHeap[T]) Push

func (t *OrderedHeap[T]) Push(x any)

Push appends the value x to the heap.

func (OrderedHeap[_]) Swap

func (t OrderedHeap[_]) Swap(i, j int)

Swap swaps the elements at indices i and j.

Jump to

Keyboard shortcuts

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