queue

package
v1.20.54 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Zlib Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIsFull = errors.New("is full")
View Source
var ErrIsReleased = errors.New("size is zero")
View Source
var PriorityType = reflect.TypeOf((*IPriority)(nil)).Elem()

Functions

func Run

func Run(c RunCall, lock sync.Locker, qu Queue)

Types

type Circular

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

Circular 环型队列

func NewCircular

func NewCircular(size int, resetFunc ResetFunc) *Circular

func (*Circular) Add

func (cr *Circular) Add(it interface{}) error

func (*Circular) Empty

func (cr *Circular) Empty() bool

func (*Circular) Find

func (cr *Circular) Find(fn IndexFunc) (interface{}, int)

Find return index -1 not found.

func (*Circular) Len

func (cr *Circular) Len() int

func (*Circular) Next

func (cr *Circular) Next(index int) (interface{}, int)

func (*Circular) Peek

func (cr *Circular) Peek() interface{}

func (*Circular) Pop

func (cr *Circular) Pop() interface{}

func (*Circular) Reset

func (cr *Circular) Reset()

type IPriority added in v1.3.58

type IPriority interface {
	GValue() interface{}
	PValue() int64 //优先级值,越小越前
}

func NewPriorityItem added in v1.3.58

func NewPriorityItem(elem interface{}) IPriority

type IndexFunc

type IndexFunc func(v interface{}, index int) bool

type LQueue

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

LQueue 链表式队列

func NewLQueue

func NewLQueue(capacity int) *LQueue

func (*LQueue) Add

func (lq *LQueue) Add(val interface{}) error

func (*LQueue) AddTail

func (lq *LQueue) AddTail(val interface{}) error

func (*LQueue) Cap

func (lq *LQueue) Cap() int

func (*LQueue) Empty

func (lq *LQueue) Empty() bool

func (*LQueue) Find

func (lq *LQueue) Find(fn IndexFunc) (interface{}, int)

Find return index -1 not found.

func (*LQueue) Len

func (lq *LQueue) Len() int

func (*LQueue) Peek

func (lq *LQueue) Peek() interface{}

func (*LQueue) Pop

func (lq *LQueue) Pop() interface{}

func (*LQueue) ToList

func (lq *LQueue) ToList() []interface{}

type Node

type Node []IPriority

type PQueue

type PQueue []IPriority

PQueue 优先级

func (*PQueue) Add

func (pq *PQueue) Add(elem interface{}) error

func (*PQueue) Empty

func (pq *PQueue) Empty() bool

func (*PQueue) Find

func (pq *PQueue) Find(fn IndexFunc) (interface{}, int)

Find return index -1 not found.

func (*PQueue) Head

func (pq *PQueue) Head() IPriority

Head returns the first item of a PQueue without removing it.

func (PQueue) Len

func (pq PQueue) Len() int

Len returns the PQueue length.

func (PQueue) Less

func (pq PQueue) Less(i, j int) bool

Less 权重越少越大前面

func (*PQueue) Peek

func (pq *PQueue) Peek() interface{}

func (*PQueue) Pop

func (pq *PQueue) Pop() interface{}

Pop implements the heap.Interface.Pop. Removes and returns element Len() - 1.

func (*PQueue) Push

func (pq *PQueue) Push(x interface{})

Push implements the heap.Interface.Push. Adds x as element Len().

func (*PQueue) Remove

func (pq *PQueue) Remove(i int) interface{}

Remove removes and returns the element at index i from the PQueue.

func (PQueue) Swap

func (pq PQueue) Swap(i, j int)

Swap exchanges the indexes of the items.

type PriorityItem

type PriorityItem struct {
	Value    interface{}
	Priority int64
}

PriorityItem 优先级

func (*PriorityItem) GValue

func (it *PriorityItem) GValue() interface{}

func (*PriorityItem) PValue

func (it *PriorityItem) PValue() int64

type Queue

type Queue interface {
	Add(elem interface{}) error
	Pop() interface{}
	Peek() interface{}
	Find(fn IndexFunc) (interface{}, int)
	Empty() bool
	Len() int
}

type ResetFunc

type ResetFunc func()

type RunCall added in v1.3.26

type RunCall struct {
	PopCount int
	Duration time.Duration
	Wait     func(dur time.Duration)
	Begin    func(count int) interface{}
	Process  func(be interface{}, data interface{})
}

type SQueue

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

SQueue 固定长度的队列

func NewSQueue

func NewSQueue(capacity int) *SQueue

func (*SQueue) Add

func (sq *SQueue) Add(elem interface{}) error

func (*SQueue) Empty

func (sq *SQueue) Empty() bool

func (*SQueue) Find

func (sq *SQueue) Find(fn IndexFunc) (interface{}, int)

Find return index -1 not found.

func (*SQueue) Get

func (sq *SQueue) Get(index int) interface{}

Get index -1 refers to the last.

func (*SQueue) Len

func (sq *SQueue) Len() int

func (*SQueue) Less

func (sq *SQueue) Less(i, j int) bool

Less 权重越少,越在前面

func (*SQueue) Peek

func (sq *SQueue) Peek() interface{}

func (*SQueue) Pop

func (sq *SQueue) Pop() interface{}

func (*SQueue) Push

func (sq *SQueue) Push(elem interface{})

Push implements the heap.Interface.Push. Adds x as element Len().

func (*SQueue) Swap

func (sq *SQueue) Swap(i, j int)

Swap swaps the elements with indexes i and j.

func (*SQueue) ToList

func (sq *SQueue) ToList() []interface{}

Jump to

Keyboard shortcuts

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