container

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

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
}

Set 是一个通用的集合(Set)数据结构。 它可以被配置为线程安全的(并发的)或非线程安全的。

必须使用 NewSet() 或 NewConcurrentSet() 来创建实例。

func NewConcurrentSet added in v0.1.8

func NewConcurrentSet[T comparable](values ...T) *Set[T]

NewConcurrentSet 线程安全的集合,可以传入初始值。

func NewSet

func NewSet[T comparable](values ...T) *Set[T]

NewSet 非线程安全的集合,可以传入初始值。

func (*Set[T]) Add

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

Add 向集合中添加一个或多个元素。

func (*Set[T]) Clear

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

Clear 清空集合中的所有元素。

func (*Set[T]) Clone

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

Clone 创建并返回当前集合的一个浅拷贝。

func (*Set[T]) Contains

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

Contains 检查集合中是否存在指定的元素。

func (*Set[T]) Difference

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

Difference 差集。

func (*Set[T]) Each

func (s *Set[T]) Each(f func(item T) bool)

Each 遍历集合中的所有元素,并对每个元素执行给定的函数。

func (*Set[T]) Equal

func (s *Set[T]) Equal(other *Set[T]) bool

Equal 检查两个集合是否相等。

func (*Set[T]) Intersection

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

Intersection 交集。

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

IsEmpty 检查集合是否为空。

func (*Set[T]) IsSubset

func (s *Set[T]) IsSubset(other *Set[T]) bool

IsSubset 检查当前集合是否是另一个集合的子集。

func (*Set[T]) IsSuperset

func (s *Set[T]) IsSuperset(other *Set[T]) bool

IsSuperset 检查当前集合是否是另一个集合的超集。

func (*Set[T]) Len

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

Len 返回集合中的元素数量。

func (*Set[T]) Remove

func (s *Set[T]) Remove(values ...T)

Remove 从集合中移除一个或多个元素。

func (*Set[T]) String

func (s *Set[T]) String() string

String 实现了 fmt.Stringer 接口,用于打印集合内容。

func (*Set[T]) SymmetricDifference

func (s *Set[T]) SymmetricDifference(other *Set[T]) *Set[T]

SymmetricDifference 对称差集。

func (*Set[T]) ToSlice

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

ToSlice 将集合中的元素转换为一个切片。

func (*Set[T]) Union

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

Union 并集。

Jump to

Keyboard shortcuts

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