Documentation ¶
Index ¶
- type Set
- func (s Set[T]) Add(items ...T)
- func (s Set[T]) AddIfNotExist(item T) bool
- func (s Set[T]) AddIfNotExistBy(item T, checker func(element T) bool) bool
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Contain(item T) bool
- func (s Set[T]) ContainAll(other Set[T]) bool
- func (s Set[T]) Delete(items ...T)
- func (s Set[T]) Equal(other Set[T]) bool
- func (s Set[T]) Intersection(other Set[T]) Set[T]
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) Iterate(fn func(item T))
- func (s Set[T]) Minus(comparedSet Set[T]) Set[T]
- func (s Set[T]) Size() int
- func (s Set[T]) SymmetricDifference(other Set[T]) Set[T]
- func (s Set[T]) Union(other Set[T]) Set[T]
- func (s Set[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
Set is a data container, like slice, but element of set is not duplicate
func NewSetFromSlice ¶
func NewSetFromSlice[T comparable](items []T) Set[T]
NewSetFromSlice create a set from slice
func (Set[T]) AddIfNotExist ¶
AddIfNotExist checks if item exists in the set, it adds the item to set and returns true if it does not exist in the set, or else it does nothing and returns false.
func (Set[T]) AddIfNotExistBy ¶
AddIfNotExistBy checks if item exists in the set and pass the `checker` function it adds the item to set and returns true if it does not exists in the set and function `checker` returns true, or else it does nothing and returns false.
func (Set[T]) ContainAll ¶
ContainAll checks if set contains other set
func (Set[T]) Intersection ¶
Intersection creates a new set whose element both be contained in set s and other
func (Set[T]) Iterate ¶
func (s Set[T]) Iterate(fn func(item T))
Iterate call function by every element of set
func (Set[T]) SymmetricDifference ¶
SymmetricDifference creates a new set whose element is in set1 or set2, but not in both sets