Documentation ¶
Overview ¶
Package datastructure contains some data structure. Set is a data container, like slice, but element of set is not duplicate.
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]) EachWithBreak(iteratee func(item T) bool)
- 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]) Pop() (v T, ok bool)
- 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 ¶ added in v2.1.11
func NewSetFromSlice[T comparable](items []T) Set[T]
NewSetFromSlice create a set from slice
func (Set[T]) AddIfNotExist ¶ added in v2.1.11
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 ¶ added in v2.1.11
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]) EachWithBreak ¶ added in v2.1.17
EachWithBreak iterates over elements of a set and invokes function for each element, when iteratee return false, will break the for each loop.
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]) Minus ¶ added in v2.0.3
Minus creates an set of whose element in origin set but not in compared set
func (Set[T]) Pop ¶ added in v2.1.17
Pop delete the top element of set then return it, if set is empty, return nil-value of T and false.
func (Set[T]) SymmetricDifference ¶ added in v2.0.3
SymmetricDifference creates a new set whose element is in set1 or set2, but not in both sets