set

package
v0.0.0-...-5c98b36 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MulanPSL-2.0 Imports: 4 Imported by: 0

README

set 集合,一组不重复数据元素集合

  • hashset 由 hashmap 实现的集合,数据元素是无序的
  • arrset 由 array 实现的集合,数据元素是排序的

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 集合,包含一组不重复出现的元素 数据项必须是可以排序的

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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