xslices

package
v0.0.0-...-5c722c9 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 2 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](slice []T, pred func(T) bool) bool

func Any

func Any[T any](slice []T, pred func(T) bool) bool

func Contains

func Contains[T comparable](slice []T, x T) bool

func ContainsWhere

func ContainsWhere[T comparable](slice []T, pred func(T) bool) bool

func CountIf

func CountIf[T any](slice []T, pred func(T) bool) int

func Diff

func Diff[T comparable](s1, s2 []T) []T

func Equal

func Equal[T comparable](s1, s2 []T) bool

func Find

func Find[T any](slice []T, pred func(*T) bool) *T

func Index

func Index[T comparable](slice []T, x T) int

func IndexWhere

func IndexWhere[T any](slice []T, pred func(T) bool) int

func Prepend

func Prepend[T any](slice []T, elems ...T) []T

func Remove

func Remove[T comparable](slice []T, x T) []T

func RemoveAt

func RemoveAt[T any](slice []T, i int) []T

func RemoveIf

func RemoveIf[T any](slice []T, pred func(T) bool) []T

func Sort

func Sort[T constraints.Ordered](slice []T)

func SortFunc

func SortFunc[S ~[]E, E any](slice S, less func(a, b E) bool)

func SortStableFunc

func SortStableFunc[S ~[]E, E any](slice S, less func(a, b E) bool)

Types

type Set

type Set[T comparable] []T

Set implements a map[T]struct{} like data structure using slices.

Most operations have a linear time complexity.

This structure is useful for small sets of values when you want to re-use the memory. It also consumes less memory than a real map-based implementation.

To get the set length, use `len(*s)`. To iterate over the set, use `for _, x := range *s`.

func NewSet

func NewSet[T comparable](capacity int) *Set[T]

NewSet creates a fresh empty slice-based set. The capacity argument is used to initialize the underlying slice.

func (*Set[T]) Add

func (s *Set[T]) Add(x T) bool

Add tries to insert x to a set. It returns true if the element was not in the set and it was added. If false is returned, the set already had that element.

func (*Set[T]) Contains

func (s *Set[T]) Contains(x T) bool

Contains reports whether this set contains x.

func (*Set[T]) Reset

func (s *Set[T]) Reset()

Jump to

Keyboard shortcuts

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