Documentation
¶
Index ¶
- type Set
- func (s *Set[T]) Add(elements ...T)
- func (s *Set[T]) AddAll(elements []T)
- func (s *Set[T]) All() []T
- func (s *Set[T]) Contains(element T) bool
- func (s *Set[T]) ContainsOrAdd(element T) (added bool)
- func (s *Set[T]) Difference(another *Set[T]) *Set[T]
- func (s *Set[T]) Do(f func(T))
- func (s *Set[T]) DoE(f func(T) error) error
- func (s *Set[T]) Has(element T) bool
- func (s *Set[T]) Insert(elements ...T)
- func (s *Set[T]) InsertAll(elements []T)
- func (s *Set[T]) Intersection(another *Set[T]) *Set[T]
- func (s *Set[T]) Len() int
- func (s *Set[T]) ProperSubsetOf(another *Set[T]) bool
- func (s *Set[T]) Remove(element T)
- func (s *Set[T]) Size() int
- func (s *Set[T]) SubsetOf(set *Set[T]) bool
- func (s *Set[T]) Union(set *Set[T]) *Set[T]
- type SyncSet
- func (s *SyncSet[T]) Add(elements ...T)
- func (s *SyncSet[T]) AddAll(elements []T)
- func (s *SyncSet[T]) All() (all []T)
- func (s *SyncSet[T]) ContainsOrAdd(element T) (added bool)
- func (s *SyncSet[T]) Has(element T) (exists bool)
- func (s *SyncSet[T]) Len() (size int)
- func (s *SyncSet[T]) Remove(element T)
- func (s *SyncSet[T]) Size() (size int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
func Intersection ¶
func Intersection[T comparable](sets ...*Set[T]) *Set[T]
Intersection 返回若干个 set 的交集
func New ¶
func New[T comparable](initial ...T) *Set[T]
New Create a new set The capacity of created set is length of initial, if you want to customize it, please use WithCapacity and .Insert / .InsertAll
func WithCapacity ¶
func WithCapacity[T comparable](capacity int) *Set[T]
WithCapacity Create an empty set with specific capacity
func (*Set[T]) ContainsOrAdd ¶ added in v0.4.24
ContainsOrAdd add element if not exist
func (*Set[T]) Difference ¶
Difference Find the difference between two sets 返回的是自己存在而传入的 set 不存在的元素集合
func (*Set[T]) InsertAll ¶
func (s *Set[T]) InsertAll(elements []T)
InsertAll add elements to the set
func (*Set[T]) Intersection ¶
Intersection Find the intersection of two sets
func (*Set[T]) ProperSubsetOf ¶
ProperSubsetOf Test whether this set is a proper subset of "set"
type SyncSet ¶ added in v0.4.24
type SyncSet[T comparable] struct { // contains filtered or unexported fields }
SyncSet provide nearly same methods as Set, but it is thread-safe
func NewSync ¶ added in v0.4.24
func NewSync[T comparable](initial ...T) *SyncSet[T]
NewSync Create a new SyncSet
func NewSyncWithCapacity ¶ added in v0.4.24
func NewSyncWithCapacity[T comparable](capacity int) *SyncSet[T]
NewSyncWithCapacity Create an empty SyncSet with specific capacity
func (*SyncSet[T]) Add ¶ added in v0.4.24
func (s *SyncSet[T]) Add(elements ...T)
Add element(s) to the set
func (*SyncSet[T]) AddAll ¶ added in v0.4.24
func (s *SyncSet[T]) AddAll(elements []T)
AddAll add elements to the set
func (*SyncSet[T]) ContainsOrAdd ¶ added in v0.4.24
ContainsOrAdd add element if not exist