Documentation
¶
Index ¶
- type ChanQueue
- func (q *ChanQueue[T]) Clear()
- func (q *ChanQueue[T]) Dequeue() (element T, ok bool)
- func (q *ChanQueue[T]) Enqueue(values ...T)
- func (q *ChanQueue[T]) EnqueueSequence(seq iter.Seq[T])
- func (q *ChanQueue[T]) IsEmpty() bool
- func (q *ChanQueue[T]) Len() int
- func (q *ChanQueue[T]) Peek() (element T, ok bool)
- func (q *ChanQueue[T]) Values() iter.Seq[T]
- type IQueue
- type Queue
- func (s *Queue[T]) Clear()
- func (s *Queue[T]) Dequeue() (element T, ok bool)
- func (s *Queue[T]) Enqueue(value ...T)
- func (s *Queue[T]) EnqueueSequence(seq iter.Seq[T])
- func (s *Queue[T]) IsEmpty() bool
- func (s *Queue[T]) Len() int
- func (s *Queue[T]) Peek() (element T, ok bool)
- func (s *Queue[T]) Values() iter.Seq[T]
- type SafeQueue
- func (q *SafeQueue[T]) Clear()
- func (q *SafeQueue[T]) Dequeue() (T, bool)
- func (q *SafeQueue[T]) Enqueue(value ...T)
- func (q *SafeQueue[T]) EnqueueSequence(seq iter.Seq[T])
- func (q *SafeQueue[T]) IsEmpty() bool
- func (q *SafeQueue[T]) Len() int
- func (q *SafeQueue[T]) Peek() (T, bool)
- func (q *SafeQueue[T]) Values() iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChanQueue ¶
type ChanQueue[T any] struct { // contains filtered or unexported fields }
ChanQueue is a channel-backed implementation of IQueue.
All methods are safe for concurrent use. Enqueue blocks when the queue is full, while Dequeue and Peek are non-blocking and return the zero value when the queue is empty. The queue has a fixed capacity defined at creation time. If performance is not enough, worth looking at https://github.com/alphadose/ZenQ
func (*ChanQueue[T]) Clear ¶
func (q *ChanQueue[T]) Clear()
Clear removes all elements from the queue.
func (*ChanQueue[T]) Dequeue ¶
Dequeue removes and returns the next element. If the queue is empty, it returns the zero value.
func (*ChanQueue[T]) Enqueue ¶
func (q *ChanQueue[T]) Enqueue(values ...T)
Enqueue adds one or more elements to the queue. This blocks if the queue is full.
func (*ChanQueue[T]) EnqueueSequence ¶
EnqueueSequence adds a sequence to the queue. This blocks if the queue is full.
type IQueue ¶
type IQueue[T any] interface { // Enqueue adds an element to the queue. Enqueue(value ...T) // EnqueueSequence adds an element to the queue. EnqueueSequence(value iter.Seq[T]) // Dequeue removes and returns an element from the queue. It returns ok true if the queue is not empty. Dequeue() (element T, ok bool) // Peek returns the element at the front of the queue without removing it. It returns ok true if the queue is not empty. Peek() (element T, ok bool) // IsEmpty states whether the queue is empty. IsEmpty() bool // Clear removes all elements from the queue. Clear() // Values returns all the elements in the queue. The queue will be empty as a result. Values() iter.Seq[T] // Len returns the number of elements in the queue. Len() int }
IQueue specifies the behaviour of a first-in, first-out (FIFO) collection. It is inspired by the work of https://github.com/hayageek/threadsafe/ and https://github.com/golang-collections/collections.
func NewChannelQueue ¶
NewChannelQueue creates a new channel-backed queue with the given capacity. Capacity must be > 0.
func NewThreadSafeQueue ¶
NewThreadSafeQueue returns a thread safe queue using mutex. This is inspired from https://github.com/hayageek/threadsafe.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
func (*Queue[T]) EnqueueSequence ¶
type SafeQueue ¶
type SafeQueue[T any] struct { // contains filtered or unexported fields }
SafeQueue is a mutex-backed implementation of IQueue.
All methods are safe for concurrent use. Operations do not block on capacity; Enqueue always succeeds. Dequeue and Peek return the zero value when the queue is empty.