Documentation
¶
Index ¶
- type BlockingDeque
- type Deque
- type Queue
- type UnboundedBlockingDeque
- func (q *UnboundedBlockingDeque[T]) Close()
- func (q *UnboundedBlockingDeque[T]) Index(i int) (T, bool)
- func (q *UnboundedBlockingDeque[T]) Len() int
- func (q *UnboundedBlockingDeque[T]) List() []T
- func (q *UnboundedBlockingDeque[T]) PeekLeft() (T, bool)
- func (q *UnboundedBlockingDeque[T]) PeekRight() (T, bool)
- func (q *UnboundedBlockingDeque[T]) PopLeft() (T, bool)
- func (q *UnboundedBlockingDeque[T]) PopRight() (T, bool)
- func (q *UnboundedBlockingDeque[T]) PushLeft(elt T) bool
- func (q *UnboundedBlockingDeque[T]) PushRight(elt T) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockingDeque ¶ added in v1.9.1
type Deque ¶ added in v1.9.1
type Deque[T any] interface { // Place an element at the leftmost end of the deque. // Returns true if the element was placed in the deque. PushLeft(T) bool // Place an element at the rightmost end of the deque. // Returns true if the element was placed in the deque. PushRight(T) bool // Remove and return the leftmost element of the deque. // Returns false if the deque is empty. PopLeft() (T, bool) // Remove and return the rightmost element of the deque. // Returns false if the deque is empty. PopRight() (T, bool) // Return the leftmost element of the deque without removing it. // Returns false if the deque is empty. PeekLeft() (T, bool) // Return the rightmost element of the deque without removing it. // Returns false if the deque is empty. PeekRight() (T, bool) // Returns the element at the given index. // Returns false if the index is out of bounds. // The leftmost element is at index 0. Index(int) (T, bool) // Returns the number of elements in the deque. Len() int // Returns the elements in the deque from left to right. List() []T }
An unbounded deque (double-ended queue). See https://en.wikipedia.org/wiki/Double-ended_queue Not safe for concurrent access.
func NewUnboundedDeque ¶ added in v1.9.1
Returns a new unbounded deque with the given initial slice size. Note that the returned deque is always empty -- [initSize] is just a hint to prevent unnecessary resizing.
type Queue ¶ added in v1.9.12
type Queue[T any] interface { // Pushes [elt] onto the queue. // If the queue is full, the oldest element is evicted to make space. Push(T) // Pops the oldest element from the queue. // Returns false if the queue is empty. Pop() (T, bool) // Returns the oldest element without removing it. // Returns false if the queue is empty. Peek() (T, bool) // Returns the element at the given index without removing it. // Index(0) returns the oldest element. // Index(Len() - 1) returns the newest element. // Returns false if there is no element at that index. Index(int) (T, bool) // Returns the number of elements in the queue. Len() int // Returns the queue elements from oldest to newest. // This is an O(n) operation and should be used sparingly. List() []T }
A FIFO queue.
func NewBoundedQueue ¶ added in v1.9.12
Returns a new bounded, non-blocking queue that holds up to [maxSize] elements. When an element is evicted, [onEvict] is called with the evicted element. If [onEvict] is nil, this is a no-op. [maxSize] must be >= 1. Not safe for concurrent use.
type UnboundedBlockingDeque ¶ added in v1.14.2
UnboundedBlockingDeque is a thread-safe blocking deque with unbounded growth.
func NewUnboundedBlockingDeque ¶ added in v1.9.1
func NewUnboundedBlockingDeque[T any](initSize int) *UnboundedBlockingDeque[T]
Returns a new unbounded deque with the given initial size. Note that the returned deque is always empty -- [initSize] is just a hint to prevent unnecessary resizing.
func (*UnboundedBlockingDeque[T]) Close ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) Close()
func (*UnboundedBlockingDeque[T]) Index ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) Index(i int) (T, bool)
func (*UnboundedBlockingDeque[T]) Len ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) Len() int
func (*UnboundedBlockingDeque[T]) List ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) List() []T
func (*UnboundedBlockingDeque[T]) PeekLeft ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) PeekLeft() (T, bool)
func (*UnboundedBlockingDeque[T]) PeekRight ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) PeekRight() (T, bool)
func (*UnboundedBlockingDeque[T]) PopLeft ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) PopLeft() (T, bool)
If the deque is closed returns false.
func (*UnboundedBlockingDeque[T]) PopRight ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) PopRight() (T, bool)
If the deque is closed returns false.
func (*UnboundedBlockingDeque[T]) PushLeft ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) PushLeft(elt T) bool
If the deque is closed returns false.
func (*UnboundedBlockingDeque[T]) PushRight ¶ added in v1.14.2
func (q *UnboundedBlockingDeque[T]) PushRight(elt T) bool
If the deque is closed returns false.