Documentation
¶
Index ¶
- func All[T any](slice []T, pred func(T) bool) bool
- func Any[T any](slice []T, pred func(T) bool) bool
- func Contains[T comparable](slice []T, x T) bool
- func ContainsWhere[T comparable](slice []T, pred func(T) bool) bool
- func CountIf[T any](slice []T, pred func(T) bool) int
- func Diff[T comparable](s1, s2 []T) []T
- func Equal[T comparable](s1, s2 []T) bool
- func Find[T any](slice []T, pred func(*T) bool) *T
- func Index[T comparable](slice []T, x T) int
- func IndexWhere[T any](slice []T, pred func(T) bool) int
- func Prepend[T any](slice []T, elems ...T) []T
- func Remove[T comparable](slice []T, x T) []T
- func RemoveAt[T any](slice []T, i int) []T
- func RemoveIf[T any](slice []T, pred func(T) bool) []T
- func Sort[T constraints.Ordered](slice []T)
- func SortFunc[S ~[]E, E any](slice S, less func(a, b E) bool)
- func SortStableFunc[S ~[]E, E any](slice S, less func(a, b E) bool)
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 Diff ¶
func Diff[T comparable](s1, s2 []T) []T
func Equal ¶
func Equal[T comparable](s1, s2 []T) bool
func Index ¶
func Index[T comparable](slice []T, x T) int
func IndexWhere ¶
func Remove ¶
func Remove[T comparable](slice []T, x T) []T
func Sort ¶
func Sort[T constraints.Ordered](slice []T)
func SortStableFunc ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.