Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-10 21:51:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-11 11:26:09 * @FilePath: \go-toolbox\pkg\queue\priority_queue.go * @Description: 优先队列实现 * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-10 21:51:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-10 22:57:16 * @FilePath: \go-toolbox\pkg\queue\queue.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- type FIFOQueue
- type Item
- type LIFOQueue
- type PriorityQueue
- func (pq *PriorityQueue) Dequeue(ctx context.Context) (interface{}, error)
- func (pq *PriorityQueue) Enqueue(ctx context.Context, item interface{}, priority int) error
- func (pq *PriorityQueue) IsEmpty() bool
- func (pq *PriorityQueue) Len() int
- func (pq *PriorityQueue) Less(i, j int) bool
- func (pq *PriorityQueue) Pop() interface{}
- func (pq *PriorityQueue) Push(x interface{})
- func (pq *PriorityQueue) Size() int
- func (pq *PriorityQueue) Swap(i, j int)
- type Queue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FIFOQueue ¶
type FIFOQueue struct {
// contains filtered or unexported fields
}
FIFOQueue 实现了先进先出(FIFO)的队列
func NewFIFOQueue ¶
NewFIFOQueue 创建并返回一个新的 FIFO 队列
type LIFOQueue ¶
type LIFOQueue struct {
// contains filtered or unexported fields
}
LIFOQueue 实现了 LIFO 队列(栈)
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue 实现了优先队列,实际上是一个堆
func (*PriorityQueue) Dequeue ¶
func (pq *PriorityQueue) Dequeue(ctx context.Context) (interface{}, error)
Dequeue 从优先队列中取出最优先的元素,支持上下文取消
func (*PriorityQueue) Enqueue ¶
func (pq *PriorityQueue) Enqueue(ctx context.Context, item interface{}, priority int) error
Enqueue 将一个元素添加到优先队列中,支持上下文取消
func (*PriorityQueue) Less ¶
func (pq *PriorityQueue) Less(i, j int) bool
Less 判断队列中第 i 和第 j 个元素的优先级