Documentation
¶
Index ¶
- type Deque
- func (dq *Deque[T]) Back() (_ T, ok bool)
- func (dq *Deque[T]) Clear()
- func (dq *Deque[T]) Dequeue() T
- func (dq *Deque[T]) DequeueMany(max int) []T
- func (dq *Deque[T]) DequeueManyWithBuffer(max int, buf []T) []T
- func (dq *Deque[T]) Dump() []T
- func (dq *Deque[T]) Enqueue(v T)
- func (dq *Deque[T]) Front() (_ T, ok bool)
- func (dq *Deque[T]) Insert(idx int, v T)
- func (dq *Deque[T]) IsEmpty() bool
- func (dq *Deque[T]) Len() int
- func (dq *Deque[T]) Peek(idx int) T
- func (dq *Deque[T]) PopBack() T
- func (dq *Deque[T]) PopFront() T
- func (dq *Deque[T]) PushBack(v T)
- func (dq *Deque[T]) PushFront(v T)
- func (dq *Deque[T]) Range(f func(i int, v T) bool)
- func (dq *Deque[T]) Remove(idx int)
- func (dq *Deque[T]) Replace(idx int, v T)
- func (dq *Deque[T]) Swap(idx1, idx2 int)
- func (dq *Deque[T]) TryDequeue() (_ T, ok bool)
- func (dq *Deque[T]) TryPopBack() (_ T, ok bool)
- func (dq *Deque[T]) TryPopFront() (_ T, ok bool)
- type Option
- type Queue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deque ¶
type Deque[T any] struct { // contains filtered or unexported fields }
Deque is a highly optimized double-ended queue.
func (*Deque[T]) Back ¶
Back returns the last value of dq if any. The return value ok indicates whether it succeeded.
func (*Deque[T]) DequeueMany ¶
DequeueMany removes a number of values from the front of dq and returns the removed values or nil if dq is empty.
If max <= 0, DequeueMany removes and returns all the values in dq.
func (*Deque[T]) DequeueManyWithBuffer ¶
DequeueManyWithBuffer is similar to DequeueMany except that it uses buf to store the removed values as long as it has enough space.
func (*Deque[T]) Front ¶
Front returns the first value of dq if any. The return value ok indicates whether it succeeded.
func (*Deque[T]) Insert ¶
Insert inserts a new value v before the value at idx.
Insert may cause the split of a chunk inside dq. Because the size of a chunk is fixed, the amount of time taken by Insert has a reasonable limit.
func (*Deque[T]) PopBack ¶
func (dq *Deque[T]) PopBack() T
PopBack removes a value from the back of dq and returns the removed value. It panics if dq is empty.
func (*Deque[T]) PopFront ¶
func (dq *Deque[T]) PopFront() T
PopFront removes a value from the front of dq and returns the removed value. It panics if dq is empty.
func (*Deque[T]) PushBack ¶
func (dq *Deque[T]) PushBack(v T)
PushBack adds a new value at the back of dq.
func (*Deque[T]) PushFront ¶
func (dq *Deque[T]) PushFront(v T)
PushFront adds a new value at the front of dq.
func (*Deque[T]) Range ¶
Range iterates all the values in dq. Do NOT add values to dq or remove values from dq during Range.
func (*Deque[T]) Replace ¶
Replace replaces the value at idx with v. It panics if idx is out of range.
func (*Deque[T]) Swap ¶
Swap exchanges the two values at idx1 and idx2. It panics if idx1 or idx2 is out of range.
func (*Deque[T]) TryDequeue ¶
TryDequeue is an alias of TryPopFront.
func (*Deque[T]) TryPopBack ¶
TryPopBack tries to remove a value from the back of dq and returns the removed value if any. The return value ok indicates whether it succeeded.
func (*Deque[T]) TryPopFront ¶
TryPopFront tries to remove a value from the front of dq and returns the removed value if any. The return value ok indicates whether it succeeded.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue 相当于容量可无限制的channel 设置无限buffer的channel(max<=0) Enqueue 接口会阻塞直到可以元素放入队列中,阻塞的情况只在队列满的时候才会出现 Dequeue 接口会阻塞直到队列中有元素返回,阻塞的情况只在队列空的时候才会出现
func NewQueueWithSize ¶
NewQueueWithSize max代表队列元素个数上限,若小于等于0,则队列无元素上限 内部会启动一个goroutine用于channel同步,可用Destroy()方法销毁。 注意调用Destroy()后就不可执行入队出队操作,否则会一直阻塞下去。