Documentation
¶
Index ¶
- func ConcatSlices[S ~[]T, T any](slices ...S) S
- func CopySlice[S ~[]T, T any](s S) (clone S)
- func EqualSlices[S ~[]T, T comparable](s1, s2 S) bool
- func LowerDivisibleBy[T Integer](v, d T) T
- func Max[T Ordered](a, b T) T
- func Min[T Ordered](a, b T) T
- func SortSlice[S ~[]T, T Ordered](s S)
- func UpperDivisibleBy[T Integer](v, d T) T
- type Bitset
- func (set *Bitset[T]) Add(elem T) bool
- func (set *Bitset[T]) Clear()
- func (set Bitset[T]) Contains(elem T) bool
- func (set Bitset[T]) Count() int
- func (set *Bitset[T]) Del(elem T) bool
- func (set Bitset[T]) Elements() []T
- func (set Bitset[T]) Intersection(set2 Bitset[T]) Bitset[T]
- func (set Bitset[T]) IsEmpty() bool
- func (set Bitset[T]) String() string
- func (set Bitset[T]) Union(set2 Bitset[T]) Bitset[T]
- type Integer
- type LockedSet
- func (ls *LockedSet[T]) Add(member T)
- func (ls *LockedSet[T]) Clear()
- func (ls *LockedSet[T]) Contains(member T) bool
- func (ls *LockedSet[T]) Del(member T)
- func (ls *LockedSet[T]) Empty() bool
- func (ls *LockedSet[T]) TestAndAdd(member T) (added bool)
- func (ls *LockedSet[T]) TestAndDel(member T) (deleted bool)
- type Ordered
- type Set
- func (s Set[T]) Add(member T)
- func (s Set[T]) Clear()
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Contains(member T) bool
- func (s Set[T]) Count() int
- func (s Set[T]) Del(member T)
- func (s Set[T]) Empty() bool
- func (s Set[T]) ForEach(f func(T))
- func (s Set[T]) Merge(s2 Set[T])
- func (s Set[T]) TestAndAdd(member T) (added bool)
- func (s Set[T]) TestAndDel(member T) (deleted bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConcatSlices ¶
func ConcatSlices[S ~[]T, T any](slices ...S) S
ConcatSlices returns the concatenation of some slices.
func CopySlice ¶
func CopySlice[S ~[]T, T any](s S) (clone S)
CopySlice returns a shallow copy of the slice
func EqualSlices ¶
func EqualSlices[S ~[]T, T comparable](s1, s2 S) bool
EqualSlices tells if two slices are equal (the same length and all elements are equal)
func LowerDivisibleBy ¶
func LowerDivisibleBy[T Integer](v, d T) T
LowerDivisibleBy returns v rounded down to the nearest multiple of d.
func UpperDivisibleBy ¶
func UpperDivisibleBy[T Integer](v, d T) T
UpperDivisibleBy returns v rounded up to the nearest multiple of d.
Types ¶
type Bitset ¶
Bitset represents a bitset of instances of some integer type T. Operations with Bitset are NOT goroutine-safe.
func MakeBitset ¶
MakeBitset makes Bitset from the list of elements of type T.
func (*Bitset[T]) Del ¶
Del deletes element from the set. It returns true if element was actually deleted.
func (Bitset[T]) Elements ¶
func (set Bitset[T]) Elements() []T
Elements returns slice of the Bitset elements
func (Bitset[T]) Intersection ¶
Intersection returns intersection of two bitsets
type Integer ¶
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
Integer is a constraint that permits any integer type.
type LockedSet ¶
type LockedSet[T comparable] struct { // contains filtered or unexported fields }
LockedSet is the generic set of any comparable objects. It works like Set, but goroutine-safe.
func NewLockedSet ¶
func NewLockedSet[T comparable]() *LockedSet[T]
NewLockedSet creates a new LockedSet
func (*LockedSet[T]) TestAndAdd ¶
TestAndAdd adds member to the set and returns true if it was actually added.
func (*LockedSet[T]) TestAndDel ¶
TestAndDel deletes member from the set and returns true if it was actually deleted.
type Ordered ¶
type Ordered interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 |
~string
}
Ordered is a constraint that permits any ordered type, i.e., any type that supports <, <=, >= and > operations.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is the generic set of any comparable objects.
Set cannot be simultaneously accessed from multiple goroutines. If you need goroutine safety, use LockedSet.
func NewSetOf ¶
func NewSetOf[T comparable](elements ...T) Set[T]
NewSetOf creates and populates a new Set
func (Set[T]) ForEach ¶
func (s Set[T]) ForEach(f func(T))
ForEach applies function to the each member of the set
func (Set[T]) TestAndAdd ¶
TestAndAdd adds member to the set and returns true if it was actually added.
func (Set[T]) TestAndDel ¶
TestAndDel deletes member from the set and returns true if it was actually deleted.