collections

package
v0.0.0-...-491ee29 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SortedList

type SortedList[T cmp.Ordered] struct {
	// As generic access may be slower, underlying slice is exposed publicly for access in hot paths
	Slice []T
}

SortedList brings a bit of high-level programming to slice. Should not be used in hotpaths! It's around 25% slower than using slice directly.

func NewSortedList

func NewSortedList[T cmp.Ordered]() *SortedList[T]

func (*SortedList[T]) Add

func (list *SortedList[T]) Add(v T) int

Add adds item T to the list. If comparer has been set, it puts the item in a place defined by comparer's criteria. Returns index at which the item has been added.

func (*SortedList[T]) AddAll

func (list *SortedList[T]) AddAll(v []T) (idx []int)

AddAll adds items contained in []T to the list. If comparer has been set, it puts the items in a place defined by comparer's criteria. Returns indices at which items have been added.

func (*SortedList[T]) AddAllV

func (list *SortedList[T]) AddAllV(v ...T) []int

AddAllV is the same as AddAll but input is variadic.

func (*SortedList[T]) Clear

func (list *SortedList[T]) Clear()

Clear clears the list.

func (*SortedList[T]) Clone

func (list *SortedList[T]) Clone() *SortedList[T]

func (*SortedList[T]) CloneWithAddCap

func (list *SortedList[T]) CloneWithAddCap(cap int) *SortedList[T]

func (*SortedList[T]) Contains

func (list *SortedList[T]) Contains(v T) bool

Contains checks if v is present in the list.

func (*SortedList[T]) First

func (list *SortedList[T]) First() T

First returns the first item in the list.

func (*SortedList[T]) Get

func (list *SortedList[T]) Get(i int) T

Get returns the item at index i.

func (*SortedList[T]) Index

func (list *SortedList[T]) Index(v T) int

Index returns the index of v, -1 if not found.

func (*SortedList[T]) IsEmpty

func (list *SortedList[T]) IsEmpty() bool

IsEmpty returns true if list is empty.

func (*SortedList[T]) Last

func (list *SortedList[T]) Last() T

Last returns the last item in the list.

func (*SortedList[T]) Len

func (list *SortedList[T]) Len() int

Len returns the size of underlying slice.

func (*SortedList[T]) Remove

func (list *SortedList[T]) Remove(v T) int

Remove deletes first encountered v and returns its index before removal. If v has not been found, -1 is returned.

func (*SortedList[T]) RemoveAt

func (list *SortedList[T]) RemoveAt(i int) (v T)

RemoveAt deletes an item at i and returns its value before removal.

func (*SortedList[T]) RemoveRange

func (list *SortedList[T]) RemoveRange(i, j int)

RemoveRange deletes items in [i, j) range

func (*SortedList[T]) Sort

func (list *SortedList[T]) Sort()

Sort is faster than SortStable, but does not guarantee original order of equal values. If stability is critical, add additional criteria (like original index) or use SortStable.

func (*SortedList[T]) SortF

func (list *SortedList[T]) SortF(comparer func(a, b T) int)

SortF is faster than SortStableF, but does not guarantee original order of equal values. If stability is critical, add additional criteria (like original index) or use SortStableF.

func (*SortedList[T]) SortStableF

func (list *SortedList[T]) SortStableF(comparer func(a, b T) int)

SortStableF is slower than SortF, but guarantees original order of equal values.

Jump to

Keyboard shortcuts

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