Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cancelable ¶ added in v0.40.0
type Cancelable struct {
// contains filtered or unexported fields
}
func (*Cancelable) IsCanceled ¶ added in v0.40.0
func (cancel *Cancelable) IsCanceled() bool
func (*Cancelable) TryCancel ¶ added in v0.40.0
func (cancel *Cancelable) TryCancel() bool
func (*Cancelable) TryRecover ¶ added in v0.40.0
func (cancel *Cancelable) TryRecover() bool
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
PriorityQueue 是一个有容量限制的优先队列,支持泛型
func NewPriorityQueue ¶
func NewPriorityQueue[T any](capacity int, better func(a, b T) bool) (*PriorityQueue[T], error)
NewPriorityQueue 创建一个新的优先队列 capacity为0表示没有容量限制 时间复杂度: O(1)
func (*PriorityQueue[T]) Dequeue ¶
func (pq *PriorityQueue[T]) Dequeue() (T, error)
Dequeue 移除并返回队列头部元素(优先级最高的元素) 时间复杂度: O(1)
func (*PriorityQueue[T]) Enqueue ¶
func (pq *PriorityQueue[T]) Enqueue(item T) error
Enqueue 添加元素到队列中,使用二分查找找到插入位置 如果超出capacity,则丢弃优先级最低的元素(队尾) 时间复杂度: O(logN) 用于二分查找,O(N) 用于元素移动(最坏情况) 整体平均时间复杂度: O(N)
func (*PriorityQueue[T]) Peek ¶
func (pq *PriorityQueue[T]) Peek() (T, error)
type PriorityScheduledTaskManager ¶ added in v0.19.0
type PriorityScheduledTaskManager struct {
// contains filtered or unexported fields
}
移除泛型 [T]
func NewPriorityScheduledTaskManager ¶ added in v0.19.0
func NewPriorityScheduledTaskManager() (*PriorityScheduledTaskManager, error)
构造函数不再需要类型参数
func (*PriorityScheduledTaskManager) FinishAndQuit ¶ added in v0.19.0
func (ptm *PriorityScheduledTaskManager) FinishAndQuit() error
func (*PriorityScheduledTaskManager) GetAllTasks ¶ added in v0.27.0
func (ptm *PriorityScheduledTaskManager) GetAllTasks() []scheduledTask
func (*PriorityScheduledTaskManager) PendNewTask ¶ added in v0.19.0
func (ptm *PriorityScheduledTaskManager) PendNewTask(action func(), runAt time.Time) (*Cancelable, error)
API 变更:直接传入函数和时间
func (*PriorityScheduledTaskManager) String ¶ added in v0.38.0
func (ptm *PriorityScheduledTaskManager) String() string
Click to show internal directories.
Click to hide internal directories.