collections

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List 是一个泛型实现的列表,但并非协程安全的 如需协程安全,请使用SafeList

func NewList

func NewList[T any]() *List[T]

func (*List[T]) Add

func (l *List[T]) Add(element T)

Add 添加一个元素

func (*List[T]) Contains

func (l *List[T]) Contains(element T) bool

Contains 判断列表是否包含某个元素

func (*List[T]) Difference

func (l *List[T]) Difference(other *List[T]) *List[T]

Difference 取差集,返回一个新的列表,其中元素是l中存在,但other中不存在的元素

func (*List[T]) Elements

func (l *List[T]) Elements() []T

Elements 获取列表中的所有元素

func (*List[T]) Get

func (l *List[T]) Get(index int) T

Get 获取指定位置的元素

func (*List[T]) Remove

func (l *List[T]) Remove(element T)

Remove 删除一个元素

func (*List[T]) Size

func (l *List[T]) Size() int

Size 获取列表长度

type SafeList

type SafeList[T any] struct {
	// contains filtered or unexported fields
}

SafeList 是一个泛型实现的列表,是协程安全的

func NewSafeList

func NewSafeList[T any]() *SafeList[T]

func (*SafeList[T]) Add

func (l *SafeList[T]) Add(element T)

Add 添加一个元素

func (*SafeList[T]) Contains

func (l *SafeList[T]) Contains(element T) bool

Contains 判断列表是否包含某个元素

func (*SafeList[T]) Difference

func (l *SafeList[T]) Difference(other *SafeList[T]) *SafeList[T]

Difference 取差集,返回一个新的列表,其中元素l中存在,但other中不存在的元素

func (*SafeList[T]) Elements

func (l *SafeList[T]) Elements() []T

Elements 获取列表中的所有元素

func (*SafeList[T]) Get

func (l *SafeList[T]) Get(index int) T

Get 获取指定位置的元素

func (*SafeList[T]) Remove

func (l *SafeList[T]) Remove(element T)

Remove 删除一个元素

func (*SafeList[T]) Size

func (l *SafeList[T]) Size() int

Size 获取列表长度

type SuperMap

type SuperMap[K int | string, V any] struct {
	// contains filtered or unexported fields
}

func NewSuperMap

func NewSuperMap[K int | string, V any]() *SuperMap[K, V]

func (*SuperMap[K, V]) Add

func (m *SuperMap[K, V]) Add(key K, value V)

Add 添加一个元素

func (*SuperMap[K, V]) Clear

func (m *SuperMap[K, V]) Clear()

Clear 清空列表

func (*SuperMap[K, V]) Contains

func (m *SuperMap[K, V]) Contains(key K) bool

Contains 判断列表是否包含某个元素

func (*SuperMap[K, V]) Equal

func (m *SuperMap[K, V]) Equal(other *SuperMap[K, V]) bool

Equal 判断两个列表是否相等

func (*SuperMap[K, V]) Filter

func (m *SuperMap[K, V]) Filter(fn func(key K, value V) bool) *SuperMap[K, V]

Filter 过滤列表

func (*SuperMap[K, V]) Foreach added in v1.1.1

func (m *SuperMap[K, V]) Foreach(fn func(key K, value V))

ForEach 遍历列表

func (*SuperMap[K, V]) Get

func (m *SuperMap[K, V]) Get(key K) V

Get 获取指定位置的元素

func (*SuperMap[K, V]) IsEmpty

func (m *SuperMap[K, V]) IsEmpty() bool

IsEmpty 判断列表是否为空

func (*SuperMap[K, V]) Keys

func (m *SuperMap[K, V]) Keys() []K

Keys 获取所有的key

func (*SuperMap[K, V]) Remove

func (m *SuperMap[K, V]) Remove(key K)

Remove 删除一个元素

func (*SuperMap[K, V]) Size

func (m *SuperMap[K, V]) Size() int

Size 获取列表长度

func (*SuperMap[K, V]) Update

func (m *SuperMap[K, V]) Update(other *SuperMap[K, V]) *SuperMap[K, V]

Update 更新列表,将other中的元素添加到m中,并返回已更新的kv。Key不存在或者Value不相等的情况下才会更新

func (*SuperMap[K, V]) Values

func (m *SuperMap[K, V]) Values() []V

Values 获取所有的value

type TTLMap

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

TTLMap 是一个带有过期时间的map

func NewTTLMap

func NewTTLMap(cleanTick time.Duration) *TTLMap

NewTTLMap 创建一个TTLMap cleanTick 清理过期数据的时间间隔

func (*TTLMap) Delete

func (m *TTLMap) Delete(key string)

Delete 删除一个key-value对

func (*TTLMap) Get

func (m *TTLMap) Get(key string) (interface{}, bool)

Get 获取一个key-value对

func (*TTLMap) Len

func (m *TTLMap) Len() int

Len 返回map的长度

func (*TTLMap) Set

func (m *TTLMap) Set(key string, value interface{}, expire time.Duration)

Set 设置一个key-value对,并指定过期时间

Jump to

Keyboard shortcuts

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