queue

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: Apache-2.0 Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package queue provides a fast, ring-buffer queue based on the version suggested by Dariusz Górecki. Using this instead of other, simpler, queue implementations (slice+append or linked list) provides substantial memory and time benefits, and fewer GC pauses.

The queue implemented here is as fast as it is for an additional reason: it is *not* thread-safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Value    interface{} // The Value of the item; arbitrary.
	Priority int         // The Priority of the item in the queue.
	// The Index is needed by update and is maintained by the heap.Interface methods.
	Index int // The Index of the item in the heap.
}

An Item is something we manage in a Priority queue.

type PriorityQueue

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

func (*PriorityQueue) Init

func (pq *PriorityQueue) Init(initItemSliceNum int)

参数是数据大小

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() *Item

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(item *Item)

func (*PriorityQueue) Remove

func (pq *PriorityQueue) Remove(item *Item)

func (*PriorityQueue) Update

func (pq *PriorityQueue) Update(item *Item, value interface{}, priority int)

type PriorityQueueSlice

type PriorityQueueSlice []*Item

A PriorityQueueSlice implements heap.Interface and holds Items.

func (PriorityQueueSlice) Len

func (pq PriorityQueueSlice) Len() int

func (PriorityQueueSlice) Less

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

func (*PriorityQueueSlice) Pop

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

func (*PriorityQueueSlice) Push

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

func (PriorityQueueSlice) Swap

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

func (*PriorityQueueSlice) Update

func (pq *PriorityQueueSlice) Update(item *Item, value interface{}, priority int)

update modifies the Priority and Value of an Item in the queue.

type Queue

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

Queue represents a single instance of the queue data structure.

func NewQueue

func NewQueue() *Queue

New constructs and returns a new Queue.

func (*Queue) Add

func (q *Queue) Add(elem interface{})

Add puts an element on the end of the queue.

func (*Queue) Get

func (q *Queue) Get(i int) interface{}

Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.

func (*Queue) Length

func (q *Queue) Length() int

Length returns the number of elements currently stored in the queue.

func (*Queue) Peek

func (q *Queue) Peek() interface{}

Peek returns the element at the head of the queue. This call panics if the queue is empty.

func (*Queue) Pop

func (q *Queue) Pop() interface{}

Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.

type SCursor added in v1.18.3

type SCursor[ElementType any] struct {
	// contains filtered or unexported fields
}

游标,通过该游标获取数据

func (*SCursor[ElementType]) First added in v1.18.3

func (s *SCursor[ElementType]) First()

游标移动到队首

func (*SCursor[ElementType]) Next added in v1.18.3

func (s *SCursor[ElementType]) Next() (elem ElementType, ret bool)

从当前位置移动游标,注意如果在多协程读或者pop时,可能会导致游标失效

type SQueue added in v1.18.3

type SQueue[ElementType any] struct {
	// contains filtered or unexported fields
}

这是一个循环队列

func NewSQueue added in v1.18.3

func NewSQueue[ElementType any](maxElementNum int) *SQueue[ElementType]

func (*SQueue[ElementType]) GetCursor added in v1.18.3

func (s *SQueue[ElementType]) GetCursor() (cur SCursor[ElementType])

获取游标,默认是队首

func (*SQueue[ElementType]) GetPosCursor added in v1.18.3

func (s *SQueue[ElementType]) GetPosCursor(pos int) (cur SCursor[ElementType], ret bool)

获取指定位置的游标

func (*SQueue[ElementType]) IsEmpty added in v1.18.3

func (s *SQueue[ElementType]) IsEmpty() bool

判断队列是否为空

func (*SQueue[ElementType]) IsFull added in v1.18.3

func (s *SQueue[ElementType]) IsFull() bool

判断队列是否已满

func (*SQueue[ElementType]) Len added in v1.18.3

func (s *SQueue[ElementType]) Len() int

获取队列元数个数

func (*SQueue[ElementType]) Pop added in v1.18.3

func (s *SQueue[ElementType]) Pop() (elem ElementType, ret bool)

从队首Pop元素

func (*SQueue[ElementType]) Push added in v1.18.3

func (s *SQueue[ElementType]) Push(elem ElementType) bool

从队尾Push数据

func (*SQueue[ElementType]) RemoveElement added in v1.18.3

func (s *SQueue[ElementType]) RemoveElement(elementNum int) (removeNum int)

从队首移除掉指定数量元素

type SyncQueue

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

func NewSyncQueue

func NewSyncQueue() *SyncQueue

func (*SyncQueue) Add

func (q *SyncQueue) Add(elem interface{})

func (*SyncQueue) Get

func (q *SyncQueue) Get(i int) interface{}

func (*SyncQueue) Len

func (q *SyncQueue) Len() int

func (*SyncQueue) Peek

func (q *SyncQueue) Peek() interface{}

func (*SyncQueue) Pop

func (q *SyncQueue) Pop() interface{}

func (*SyncQueue) RLockRange

func (q *SyncQueue) RLockRange(f func(interface{}))

Jump to

Keyboard shortcuts

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