queue

package module
v0.0.0-...-4191569 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 1 Imported by: 7

README

Queue

When using the go language, we often use bytes.Buffer for byte stream reading and writing. Can I have a queue like bytes.Buffer?It can read and write to stream of any type stream. That's why I wrote this queue. In fact most of its code is copied from bytes.Buffer.

The queue is not thread-safe, thread-safe is handled by the caller himself

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elem

type Elem = interface{}

Elem represents an element of a queue.

type Queue

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

Queue represents a queue. The zero value for Queue is an empty queue ready to use.

func New

func New(buf []Elem) *Queue

New creates and initializes a new Queue using buf as its initial contents. The new Queue takes ownership of buf, and the caller should not use buf after this call. New is intended to prepare a Queue to read existing data. It can also be used to set the initial size of the internal queue for writing. To do that, buf should have the desired capacity but a length of zero.

In most cases, new(Queue) (or just declaring a Queue variable) is sufficient to initialize a Queue.

func (*Queue) Cap

func (q *Queue) Cap() int

Cap returns the capacity of the queue's underlying slice

func (*Queue) Elems

func (q *Queue) Elems() []Elem

Elems return all elements of queue.

func (*Queue) Empty

func (q *Queue) Empty() bool

Empty determines if the queue is empty.

func (*Queue) Get

func (q *Queue) Get(i int) (e Elem)

Get returns the element at index i in the queue. If the index is invalid, the call will panic.

func (*Queue) Grow

func (q *Queue) Grow(n int)

Grow grows the queue's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be pushed to the queue without another allocation. If n is negative, Grow will panic.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the number of elements of queue; q.Len() == len(q.Elems()).

func (*Queue) Pop

func (q *Queue) Pop() (v Elem, ok bool)

Pop removes and returns the front element from the queue. Ok is true if the queue is empty, otherwise is false.

func (*Queue) PopN

func (q *Queue) PopN(elems []Elem) (n int)

PopN copies and removes the front len(elems) elements from the queue or until the queue is drained. The return value n is the number of elements copied.

func (*Queue) Push

func (q *Queue) Push(e Elem)

Push pushes the element e to the tail of the queue.

func (*Queue) PushN

func (q *Queue) PushN(elems []Elem)

PushN pushes the contents of elems to the tail of the queue.

func (*Queue) Reset

func (q *Queue) Reset()

Reset resets the queue to be empty, but it retains the underlying storage for use by future.

func (*Queue) Skip

func (q *Queue) Skip(n int) int

Skip skips the front n elements. The return value n is the number of elements discarded.

type SyncQueue

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

SyncQueue 同步队列

func NewSyncQueue

func NewSyncQueue() *SyncQueue

NewSyncQueue 创建同步队列

func (*SyncQueue) Broadcast

func (q *SyncQueue) Broadcast()

Broadcast 广播信号,以释放所有出列的阻塞等待

func (*SyncQueue) Len

func (q *SyncQueue) Len() int

Len 队列长度

func (*SyncQueue) Pop

func (q *SyncQueue) Pop() Elem

Pop 出列,如果没有等待信号做一次重试

func (*SyncQueue) Push

func (q *SyncQueue) Push(e Elem)

Push 入列并发送信号

func (*SyncQueue) Queue

func (q *SyncQueue) Queue() *Queue

Queue 返回内部队列

func (*SyncQueue) Reset

func (q *SyncQueue) Reset()

Reset 重置队列

func (*SyncQueue) Signal

func (q *SyncQueue) Signal()

Signal 发送信号,以便结束等待

Jump to

Keyboard shortcuts

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