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]) ToSlice() []T
- func (s Set[T]) ToSortedSlice(less func(v1, v2 T) bool) []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 FromSlice ¶
func FromSlice[T comparable](items []T) Set[T]
FromSlice create a set from given slice.
func New ¶
func New[T comparable](items ...T) Set[T]
New create a instance of set from given values.
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]) EachWithBreak ¶
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]) Pop ¶
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 ¶
SymmetricDifference creates a new set whose element is in set1 or set2, but not in both sets
func (Set[T]) ToSlice ¶
func (s Set[T]) ToSlice() []T
ToSlice returns a slice containing all values of the set.
func (Set[T]) ToSortedSlice ¶
ToSortedSlice returns a sorted slice containing all values of the set.
func (Set[T]) Values ¶
func (s Set[T]) Values() []T
Values return all values of set Deprecated: Values function is deprecated and will be removed in future versions. Please use ToSlice() function instead.
The ToSlice() function provides the same functionality as Values and returns a slice containing all values of the set.