Documentation ¶
Overview ¶
Package goqueue 延迟队列
Package goqueue 优先级队列(小顶堆)
Index ¶
- type DelayQueue
- type Element
- type PriorityQueue
- func (pq PriorityQueue) Len() int
- func (pq PriorityQueue) Less(i, j int) bool
- func (pq *PriorityQueue) Offer(val interface{}, priority int64) *Element
- func (pq PriorityQueue) Peek() *Element
- func (pq *PriorityQueue) PeekAndRemove() *Element
- func (pq *PriorityQueue) PeekAndShift(priority int64) (*Element, int64)
- func (pq *PriorityQueue) Pop() interface{}
- func (pq *PriorityQueue) Push(ele interface{})
- func (pq PriorityQueue) Swap(i, j int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DelayQueue ¶
type DelayQueue struct { C chan interface{} // you will get the ready element from this chan // contains filtered or unexported fields }
DelayQueue make your element delay to be done with a Millisecond precision
func NewDelayQueue ¶
func NewDelayQueue(size int) *DelayQueue
NewDelayQueue New DelayQueue with size
func (*DelayQueue) Offer ¶
func (dq *DelayQueue) Offer(value interface{}, runTime time.Time)
Offer add a element to queue, runTime is the future time we want to get the element
func (*DelayQueue) Poll ¶
func (dq *DelayQueue) Poll()
Poll send the ready element to a chan, you should call this func with a new goroutine to make process unblock.
func (*DelayQueue) Stop ¶
func (dq *DelayQueue) Stop()
Stop stop to check delayQueue, break loop in Poll func
type PriorityQueue ¶
type PriorityQueue []*Element
PriorityQueue no concurrency safty, need to Lock when use with multi-goroutines
func NewPriorityQueue ¶
func NewPriorityQueue(size int) PriorityQueue
NewPriorityQueue NewPriorityQueue
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Offer ¶
func (pq *PriorityQueue) Offer(val interface{}, priority int64) *Element
Offer add a val with priority
func (PriorityQueue) Peek ¶
func (pq PriorityQueue) Peek() *Element
Peek return a *Element which has the least Priority in queue
func (*PriorityQueue) PeekAndRemove ¶
func (pq *PriorityQueue) PeekAndRemove() *Element
PeekAndShift return the first *Element and delete it from queue
func (*PriorityQueue) PeekAndShift ¶
func (pq *PriorityQueue) PeekAndShift(priority int64) (*Element, int64)
PeekAndShift return a *Element which has the least Priority in queue and ele.Priority not more than param priority. Otherwise, return nil and priority-ele.Priority
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(ele interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)