gset

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntSet

type IntSet struct {
	// contains filtered or unexported fields
}

IntSet 存储不重复的整数集合

func NewIntSet

func NewIntSet(safe ...bool) *IntSet

NewIntSet 创建一个新的整数集合 safe参数用于指定是否启用并发安全,默认为false

func NewIntSetFrom

func NewIntSetFrom(items []int, safe ...bool) *IntSet

NewIntSetFrom 从整数切片创建新的集合

func (*IntSet) Add

func (set *IntSet) Add(items ...int)

Add 添加一个或多个整数到集合

func (*IntSet) Contains

func (set *IntSet) Contains(item int) bool

Contains 检查集合是否包含指定整数

func (*IntSet) Intersect

func (set *IntSet) Intersect(others ...*IntSet) *IntSet

Intersect 返回与其他集合的交集

func (*IntSet) Iterator

func (set *IntSet) Iterator(f func(v int) bool)

Iterator 使用回调函数只读遍历集合

func (*IntSet) MarshalJSON

func (set *IntSet) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshal 接口

func (*IntSet) Pop

func (set *IntSet) Pop() int

Pop 随机移除并返回一个元素

func (*IntSet) Remove

func (set *IntSet) Remove(items ...int)

Remove 从集合中删除指定整数

func (*IntSet) Size

func (set *IntSet) Size() int

Size 返回集合大小

func (*IntSet) Slice

func (set *IntSet) Slice() []int

Slice 返回包含所有元素的有序切片

func (*IntSet) String

func (set *IntSet) String() string

String 返回集合的字符串表示

func (*IntSet) Sum

func (set *IntSet) Sum() (sum int)

Sum 计算集合中所有整数的和

func (*IntSet) Union

func (set *IntSet) Union(others ...*IntSet) *IntSet

Union 返回与其他集合的并集

func (*IntSet) UnmarshalJSON

func (set *IntSet) UnmarshalJSON(b []byte) error

UnmarshalJSON 实现 json.Unmarshal 接口

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set 是一个通用的集合类型,存储不重复的items

func New

func New(safe ...bool) *Set

New 创建并返回一个新的集合 safe参数指定是否启用并发安全,默认为false

func NewFrom

func NewFrom(items interface{}, safe ...bool) *Set

NewFrom 从给定的items创建一个新的集合 items可以是任意类型的变量或切片

func NewSet

func NewSet(safe ...bool) *Set

NewSet 创建并返回一个新的集合

func (*Set) Add

func (set *Set) Add(items ...interface{})

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

func (*Set) AddIfNotExist

func (set *Set) AddIfNotExist(item interface{}) bool

AddIfNotExist 如果元素不存在则添加并返回true,否则返回false

func (*Set) Clear

func (set *Set) Clear()

Clear 清空集合

func (*Set) Contains

func (set *Set) Contains(item interface{}) bool

Contains 检查集合是否包含指定元素

func (*Set) Intersect

func (set *Set) Intersect(others ...*Set) *Set

Intersect 返回当前集合与其他集合的交集

func (*Set) Iterator

func (set *Set) Iterator(f func(v interface{}) bool)

Iterator 使用回调函数只读遍历集合 如果f返回true则继续遍历,返回false则停止

func (*Set) Remove

func (set *Set) Remove(items ...interface{})

Remove 从集合中移除指定元素

func (*Set) RemoveAll added in v0.1.8

func (set *Set) RemoveAll(other *Set)

RemoveAll 移除另一个集合中的所有元素

func (*Set) Size

func (set *Set) Size() int

Size 返回集合的大小

func (*Set) Slice

func (set *Set) Slice() []interface{}

Slice 返回包含集合所有元素的切片

func (*Set) String

func (set *Set) String() string

String 返回集合的字符串表示 String 返回集合的字符串表示,实现类似 JSON.Marshal 的效果

func (*Set) Union

func (set *Set) Union(others ...*Set) *Set

Union 返回当前集合与其他集合的并集

type StrSet

type StrSet struct {
	// contains filtered or unexported fields
}

StrSet 存储不重复的字符串集合

func NewStrSet

func NewStrSet(safe ...bool) *StrSet

NewStrSet 创建一个新的字符串集合 safe参数用于指定是否启用并发安全,默认为false

func NewStrSetFrom

func NewStrSetFrom(items []string, safe ...bool) *StrSet

NewStrSetFrom 从字符串切片创建新的集合

func (*StrSet) Add

func (set *StrSet) Add(items ...string)

Add 添加一个或多个字符串到集合

func (*StrSet) AddIfNotExist

func (set *StrSet) AddIfNotExist(item string) bool

AddIfNotExist 检查集合中是否存在项目, 它将该项添加到set中,如果该项在set中不存在,则返回true, 否则它什么也不做,返回false。

func (*StrSet) AddIfNotExistFunc

func (set *StrSet) AddIfNotExistFunc(item string, f func() bool) bool

AddIfNotExistFunc 检查集合中是否存在项目, 它将该项添加到set中,如果该项在set中不存在,则返回true,并且 函数`f`返回true,否则它什么也不做,返回false。

请注意,函数“f”是在没有写锁的情况下执行的。

func (*StrSet) AddIfNotExistFuncLock

func (set *StrSet) AddIfNotExistFuncLock(item string, f func() bool) bool

AddIfNotExistFuncLock 检查集合中是否存在项目, 它将该项添加到set中,如果该项在set中不存在,则返回true,并且 函数`f`返回true,否则它什么也不做,返回false。

请注意,函数“f”是在没有写锁的情况下执行的。

func (*StrSet) Clear

func (set *StrSet) Clear()

Clear 清空集合

func (*StrSet) Contains

func (set *StrSet) Contains(item string) bool

Contains 检查集合是否包含指定字符串

func (*StrSet) ContainsI

func (set *StrSet) ContainsI(item string) bool

ContainsI 检查集合是否包含指定字符串(不区分大小写)

func (*StrSet) Intersect

func (set *StrSet) Intersect(others ...*StrSet) *StrSet

Intersect 返回与其他集合的交集

func (*StrSet) Iterator

func (set *StrSet) Iterator(f func(v string) bool)

Iterator 使用回调函数只读遍历集合 如果回调函数返回false则停止遍历

func (*StrSet) MarshalJSON

func (set *StrSet) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*StrSet) Remove

func (set *StrSet) Remove(items ...string)

Remove 从集合中移除指定字符串

func (*StrSet) Size

func (set *StrSet) Size() int

Size 返回集合大小

func (*StrSet) Slice

func (set *StrSet) Slice() []string

Slice 返回包含所有元素的有序切片

func (*StrSet) String

func (set *StrSet) String() string

String 返回集合的字符串表示

func (*StrSet) Union

func (set *StrSet) Union(others ...*StrSet) *StrSet

Union 返回与其他集合的并集

func (*StrSet) UnmarshalJSON

func (set *StrSet) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口

Jump to

Keyboard shortcuts

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