set

package
v0.4.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

Index

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]) Add

func (s *Set[T]) Add(elements ...T)

Add element(s) to the set

func (*Set[T]) AddAll

func (s *Set[T]) AddAll(elements []T)

AddAll add elements to the set

func (*Set[T]) All

func (s *Set[T]) All() []T

func (*Set[T]) Contains

func (s *Set[T]) Contains(element T) bool

Contains Test to see whether the element is in the set

func (*Set[T]) ContainsOrAdd added in v0.4.24

func (s *Set[T]) ContainsOrAdd(element T) (added bool)

ContainsOrAdd add element if not exist

func (*Set[T]) Difference

func (s *Set[T]) Difference(another *Set[T]) *Set[T]

Difference Find the difference between two sets 返回的是自己存在而传入的 set 不存在的元素集合

func (*Set[T]) Do

func (s *Set[T]) Do(f func(T))

Do Call f for each item in the set

func (*Set[T]) DoE

func (s *Set[T]) DoE(f func(T) error) error

DoE Call f for each item in the set

func (*Set[T]) Has

func (s *Set[T]) Has(element T) bool

Has Test to see whether the element is in the set

func (*Set[T]) Insert

func (s *Set[T]) Insert(elements ...T)

Insert add element(s) to the set

func (*Set[T]) InsertAll

func (s *Set[T]) InsertAll(elements []T)

InsertAll add elements to the set

func (*Set[T]) Intersection

func (s *Set[T]) Intersection(another *Set[T]) *Set[T]

Intersection Find the intersection of two sets

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len Return the number of items in the set

func (*Set[T]) ProperSubsetOf

func (s *Set[T]) ProperSubsetOf(another *Set[T]) bool

ProperSubsetOf Test whether this set is a proper subset of "set"

func (*Set[T]) Remove

func (s *Set[T]) Remove(element T)

Remove an element from the set

func (*Set[T]) Size

func (s *Set[T]) Size() int

Size Return the number of items in the set

func (*Set[T]) SubsetOf

func (s *Set[T]) SubsetOf(set *Set[T]) bool

SubsetOf Test whether this set is a subset of "set"

func (*Set[T]) Union

func (s *Set[T]) Union(set *Set[T]) *Set[T]

Union Find the union of two sets

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]) All added in v0.4.24

func (s *SyncSet[T]) All() (all []T)

func (*SyncSet[T]) ContainsOrAdd added in v0.4.24

func (s *SyncSet[T]) ContainsOrAdd(element T) (added bool)

ContainsOrAdd add element if not exist

func (*SyncSet[T]) Has added in v0.4.24

func (s *SyncSet[T]) Has(element T) (exists bool)

Has Test to see whether the element is in the set

func (*SyncSet[T]) Len added in v0.4.24

func (s *SyncSet[T]) Len() (size int)

Len Return the number of items in the set

func (*SyncSet[T]) Remove added in v0.4.24

func (s *SyncSet[T]) Remove(element T)

Remove an element from the set

func (*SyncSet[T]) Size added in v0.4.24

func (s *SyncSet[T]) Size() (size int)

Size Return the number of items in the set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL