Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewArrSet ¶
func NewArrSet[T constraints.Ordered](initCap int, comparer func(a, b T) bool, safe bool) *arrSet[T]
NewArrSet 创建一个基于数组的集合 如果 comparer 不是 nil 则根据 comparer 进行排序,或者按照先后顺序进行排序
func NewHashSet ¶
func NewHashSet[T constraints.Ordered](initCap int, safe bool) *hashSet[T]
NewHashSet 创建一个实例
Types ¶
type Set ¶
type Set[T constraints.Ordered] interface { // Add 添加数据元素,已经存在则忽略 Add(elements ...T) // Remove 删除一个元素 Remove(elements ...T) // Contains 元素存在返回true,反之返回false Contains(ele T) bool // Iterator 迭代元素 // 当 fn 返回 false 的时候停止迭代 Iterator(fn func(ele T) bool) // Len 返回元素的数量 Len() int // Reset 清空容器 Reset() // Slice 返回切片 Slice() []T // Clone 克隆 Clone() Set[T] // Union 并集 // {1,2,3},{2,3,4} => {1,2,3,4} Union(set Set[T]) Set[T] // Intersect 交集 // {1,2,3},{2,3,4} => {2,3} Intersect(set Set[T]) Set[T] // Difference 差集 // {1,2,3},{2,3,4} => {1} Difference(set Set[T]) Set[T] // SymmetricDifference 对称差集 // {1,2,3},{2,3,4} => {1,4} SymmetricDifference(set Set[T]) Set[T] // MarshalText 实现 `encoding.TextUnmarshaler` 接口 // 用于 `json.Marshal` MarshalText() ([]byte, error) // UnmarshalText 实现 `encoding.TextUnmarshaler` 接口 UnmarshalText(data []byte) error // UnmarshalJSON 实现 `json.Unmarshaler` 接口 // 用于 `json.UnmarshalJSON` UnmarshalJSON(data []byte) error }
Set 集合,包含一组不重复出现的元素 数据项必须是可以排序的
Click to show internal directories.
Click to hide internal directories.