collections

package
v0.0.0-...-6ed9cba Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 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 MinPriorityQueue

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

MinPriorityQueue 最小优先队列实现(优先级值越小越优先)

func NewMinPriorityQueue

func NewMinPriorityQueue[T any]() *MinPriorityQueue[T]

NewMinPriorityQueue 创建新的最小优先队列

func (*MinPriorityQueue[T]) Clear

func (pq *MinPriorityQueue[T]) Clear()

Clear 清空队列

func (*MinPriorityQueue[T]) Dequeue

func (pq *MinPriorityQueue[T]) Dequeue() (T, int, error)

Dequeue 出队

func (*MinPriorityQueue[T]) Enqueue

func (pq *MinPriorityQueue[T]) Enqueue(value T, priority int) *PriorityItem[T]

Enqueue 入队

func (*MinPriorityQueue[T]) ForEach

func (pq *MinPriorityQueue[T]) ForEach(fn func(value T, priority int) bool)

ForEach 遍历优先队列(按优先级顺序)

func (*MinPriorityQueue[T]) FromSlice

func (pq *MinPriorityQueue[T]) FromSlice(items []T, priorities []int) error

FromSlice 从切片创建优先队列

func (*MinPriorityQueue[T]) IsEmpty

func (pq *MinPriorityQueue[T]) IsEmpty() bool

IsEmpty 检查队列是否为空

func (*MinPriorityQueue[T]) Len

func (pq *MinPriorityQueue[T]) Len() int

Len 实现 heap.Interface

func (*MinPriorityQueue[T]) Less

func (pq *MinPriorityQueue[T]) Less(i, j int) bool

Less 实现 heap.Interface,优先级低的在前

func (*MinPriorityQueue[T]) Peek

func (pq *MinPriorityQueue[T]) Peek() (T, int, error)

Peek 查看队首元素

func (*MinPriorityQueue[T]) Pop

func (pq *MinPriorityQueue[T]) Pop() any

Pop 实现 heap.Interface

func (*MinPriorityQueue[T]) Push

func (pq *MinPriorityQueue[T]) Push(x any)

Push 实现 heap.Interface

func (*MinPriorityQueue[T]) Size

func (pq *MinPriorityQueue[T]) Size() int

Size 获取队列大小

func (*MinPriorityQueue[T]) Swap

func (pq *MinPriorityQueue[T]) Swap(i, j int)

Swap 实现 heap.Interface

func (*MinPriorityQueue[T]) ToSlice

func (pq *MinPriorityQueue[T]) ToSlice() []T

ToSlice 转换为切片(按优先级顺序)

func (*MinPriorityQueue[T]) UpdatePriority

func (pq *MinPriorityQueue[T]) UpdatePriority(item *PriorityItem[T], priority int)

UpdatePriority 更新元素优先级

type OrderedMap

type OrderedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

OrderedMap 有序字典实现

func NewOrderedMap

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]

NewOrderedMap 创建新的有序字典

func (*OrderedMap[K, V]) Clear

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

Clear 清空字典

func (*OrderedMap[K, V]) Delete

func (m *OrderedMap[K, V]) Delete(key K)

Delete 删除键值对

func (*OrderedMap[K, V]) First

func (m *OrderedMap[K, V]) First() (K, V, error)

First 获取第一个键值对

func (*OrderedMap[K, V]) ForEach

func (m *OrderedMap[K, V]) ForEach(fn func(key K, value V) bool)

ForEach 遍历所有键值对(按插入顺序)

func (*OrderedMap[K, V]) Get

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

Get 获取值

func (*OrderedMap[K, V]) GoString

func (m *OrderedMap[K, V]) GoString() string

GoString 实现 GoStringer 接口

func (*OrderedMap[K, V]) Has

func (m *OrderedMap[K, V]) Has(key K) bool

Has 检查键是否存在

func (*OrderedMap[K, V]) Items

func (m *OrderedMap[K, V]) Items() []OrderedMapItem[K, V]

Items 获取所有键值对(按插入顺序)

func (*OrderedMap[K, V]) Keys

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

Keys 获取所有键(按插入顺序)

func (*OrderedMap[K, V]) Last

func (m *OrderedMap[K, V]) Last() (K, V, error)

Last 获取最后一个键值对

func (*OrderedMap[K, V]) Len

func (m *OrderedMap[K, V]) Len() int

Len 获取字典长度

func (*OrderedMap[K, V]) MarshalJSON

func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*OrderedMap[K, V]) Set

func (m *OrderedMap[K, V]) Set(key K, value V)

Set 设置键值对

func (*OrderedMap[K, V]) String

func (m *OrderedMap[K, V]) String() string

String 实现 Stringer 接口

func (*OrderedMap[K, V]) UnmarshalJSON

func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口

func (*OrderedMap[K, V]) Values

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

Values 获取所有值(按键的插入顺序)

type OrderedMapItem

type OrderedMapItem[K comparable, V any] struct {
	Key   K
	Value V
}

OrderedMapItem 有序字典项

type PriorityItem

type PriorityItem[T any] struct {
	Value    T
	Priority int
	// contains filtered or unexported fields
}

PriorityItem 优先队列项

type PriorityQueue

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

PriorityQueue 优先队列实现

func NewPriorityQueue

func NewPriorityQueue[T any]() *PriorityQueue[T]

NewPriorityQueue 创建新的优先队列

func (*PriorityQueue[T]) Clear

func (pq *PriorityQueue[T]) Clear()

Clear 清空队列

func (*PriorityQueue[T]) Dequeue

func (pq *PriorityQueue[T]) Dequeue() (T, int, error)

Dequeue 出队

func (*PriorityQueue[T]) Enqueue

func (pq *PriorityQueue[T]) Enqueue(value T, priority int) *PriorityItem[T]

Enqueue 入队

func (*PriorityQueue[T]) ForEach

func (pq *PriorityQueue[T]) ForEach(fn func(value T, priority int) bool)

ForEach 遍历优先队列(按优先级顺序)

func (*PriorityQueue[T]) FromSlice

func (pq *PriorityQueue[T]) FromSlice(items []T, priorities []int) error

FromSlice 从切片创建优先队列

func (*PriorityQueue[T]) IsEmpty

func (pq *PriorityQueue[T]) IsEmpty() bool

IsEmpty 检查队列是否为空

func (*PriorityQueue[T]) Len

func (pq *PriorityQueue[T]) Len() int

Len 实现 heap.Interface

func (*PriorityQueue[T]) Less

func (pq *PriorityQueue[T]) Less(i, j int) bool

Less 实现 heap.Interface,优先级高的在前

func (*PriorityQueue[T]) Peek

func (pq *PriorityQueue[T]) Peek() (T, int, error)

Peek 查看队首元素

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() any

Pop 实现 heap.Interface

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(x any)

Push 实现 heap.Interface

func (*PriorityQueue[T]) Size

func (pq *PriorityQueue[T]) Size() int

Size 获取队列大小

func (*PriorityQueue[T]) Swap

func (pq *PriorityQueue[T]) Swap(i, j int)

Swap 实现 heap.Interface

func (*PriorityQueue[T]) ToSlice

func (pq *PriorityQueue[T]) ToSlice() []T

ToSlice 转换为切片(按优先级顺序)

func (*PriorityQueue[T]) UpdatePriority

func (pq *PriorityQueue[T]) UpdatePriority(item *PriorityItem[T], priority int)

UpdatePriority 更新元素优先级

type Queue

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

Queue 泛型队列实现

func NewQueue

func NewQueue[T any]() *Queue[T]

NewQueue 创建新队列

func (*Queue[T]) Clear

func (q *Queue[T]) Clear()

Clear 清空队列

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() (item T, err error)

Dequeue 出队

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(item T)

Enqueue 入队

func (*Queue[T]) FromSlice

func (q *Queue[T]) FromSlice(items []T)

FromSlice 从切片创建队列

func (*Queue[T]) GoString

func (q *Queue[T]) GoString() string

GoString 实现 GoStringer 接口

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

IsEmpty 检查队列是否为空

func (*Queue[T]) MarshalJSON

func (q *Queue[T]) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() (item T, err error)

Peek 查看队首元素

func (*Queue[T]) Size

func (q *Queue[T]) Size() int

Size 获取队列大小

func (*Queue[T]) String

func (q *Queue[T]) String() string

String 实现 Stringer 接口

func (*Queue[T]) ToSlice

func (q *Queue[T]) ToSlice() []T

ToSlice 转换为切片

func (*Queue[T]) UnmarshalJSON

func (q *Queue[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口

type Stack

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

Stack 栈实现

func NewStack

func NewStack[T any]() *Stack[T]

NewStack 创建新栈

func (*Stack[T]) Clear

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

Clear 清空栈

func (*Stack[T]) FromSlice

func (s *Stack[T]) FromSlice(items []T)

FromSlice 从切片创建栈

func (*Stack[T]) GoString

func (s *Stack[T]) GoString() string

GoString 实现 GoStringer 接口

func (*Stack[T]) IsEmpty

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

IsEmpty 检查栈是否为空

func (*Stack[T]) MarshalJSON

func (s *Stack[T]) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (item T, err error)

Peek 查看栈顶元素

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (item T, err error)

Pop 出栈

func (*Stack[T]) Push

func (s *Stack[T]) Push(item T)

Push 压栈

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

Size 获取栈大小

func (*Stack[T]) String

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

String 实现 Stringer 接口

func (*Stack[T]) ToSlice

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

ToSlice 转换为切片

func (*Stack[T]) UnmarshalJSON

func (s *Stack[T]) 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