priq

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package priq 带优先级功的队列,可以进行select操作,并且有容量限制

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueIsFull = errors.New("queue.is.full")

Functions

This section is empty.

Types

type EntryList

type EntryList []*wrapEntry

func (EntryList) Len

func (e EntryList) Len() int

func (EntryList) Less

func (e EntryList) Less(i, j int) bool

Less 根据less从小到大排列,排在前面的先Pop(也就是优先级更高)

func (*EntryList) Pop

func (e *EntryList) Pop() interface{}

func (*EntryList) Push

func (e *EntryList) Push(x interface{})

func (EntryList) Swap

func (e EntryList) Swap(i, j int)

type IEntry

type IEntry interface {
	GetPriority() int
}

type PriQueue

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

func NewPriQueue

func NewPriQueue(capability int) *PriQueue

func (*PriQueue) Len

func (pq *PriQueue) Len() int

func (*PriQueue) Pop

func (pq *PriQueue) Pop() IEntry

Pop 不阻塞,如果返回nil代表当前队列是空的

func (*PriQueue) Push

func (pq *PriQueue) Push(e IEntry) error

Push 不阻塞

func (*PriQueue) WaitCh

func (pq *PriQueue) WaitCh() <-chan struct{}

WaitCh 对 WaitCh() 返回的channel进行select,然后再使用Pop

Jump to

Keyboard shortcuts

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