Documentation
¶
Overview ¶
Queue is a generic dynamically resizable FIFO Queue. It supports enqueue and dequeue operations in constant amortized time, and grows or shrinks based on usage to optimize memory consumption.
Index ¶
- type Queue
- func (q *Queue[T]) Cap() int
- func (q *Queue[T]) Clone() *Queue[T]
- func (q *Queue[T]) Dequeue() (T, bool)
- func (q *Queue[T]) Enqueue(values ...T)
- func (q *Queue[T]) Equals(other *Queue[T]) bool
- func (q *Queue[T]) IsEmpty() bool
- func (q *Queue[T]) Len() int
- func (q *Queue[T]) Peek() (T, bool)
- func (q *Queue[T]) ToSlice() []T
- type SyncQueue
- func (q *SyncQueue[T]) Cap() int
- func (q *SyncQueue[T]) Clone() *SyncQueue[T]
- func (q *SyncQueue[T]) Dequeue() (T, bool)
- func (q *SyncQueue[T]) Enqueue(values ...T)
- func (q *SyncQueue[T]) Equals(other *SyncQueue[T]) bool
- func (q *SyncQueue[T]) IsEmpty() bool
- func (q *SyncQueue[T]) Len() int
- func (q *SyncQueue[T]) Peek() (T, bool)
- func (q *SyncQueue[T]) ToSlice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue[T comparable] struct { // contains filtered or unexported fields }
func FromSlice ¶
func FromSlice[T comparable, A ~[]T](s A, capacity ...int) *Queue[T]
FromSlice creates a new Queue from a given slice. An optional capacity may be provided. If the capacity is less than the slice length, the slice length is used as the minimum capacity.
func FromSyncQueue ¶
func FromSyncQueue[T comparable](src *SyncQueue[T]) *Queue[T]
FromSyncQueue creates a new Queue from a given SyncQueue. This results in a deep copy so the underlying buffer won't be connected to the original SyncQueue.
func New ¶
func New[T comparable](capacity ...int) *Queue[T]
New returns a new Queue with an optional initial capacity. If no capacity is provided or the provided value is <= 0, a default of 8 is used.
func (*Queue[T]) Dequeue ¶
Dequeue removes and returns the element at the front of the buffer. If the buffer is empty, it returns the zero value of T and false. The buffer may shrink if usage falls below 25% of capacity.
func (*Queue[T]) Enqueue ¶
func (q *Queue[T]) Enqueue(values ...T)
Enqueue appends one or more values to the end of the buffer. If necessary, the buffer is resized to accommodate the new values.
type SyncQueue ¶
type SyncQueue[T comparable] struct { // contains filtered or unexported fields }
func NewSync ¶
func NewSync[T comparable](capacity ...int) *SyncQueue[T]
New returns a new Queue with an optional initial capacity. If no capacity is provided or the provided value is <= 0, a default of 8 is used.
func SyncFromQueue ¶
func SyncFromQueue[T comparable](src *Queue[T]) *SyncQueue[T]
FromSyncQueue creates a new Queue from a given SyncQueue. This results in a deep copy so the underlying buffer won't be connected to the original SyncQueue.
func SyncFromSlice ¶
func SyncFromSlice[T comparable, A ~[]T](s A, capacity ...int) *SyncQueue[T]
FromSlice creates a new Queue from a given slice. An optional capacity may be provided. If the capacity is less than the slice length, the slice length is used as the minimum capacity.
func (*SyncQueue[T]) Dequeue ¶
Dequeue removes and returns the element at the front of the buffer. If the buffer is empty, it returns the zero value of T and false. The buffer may shrink if usage falls below 25% of capacity.
func (*SyncQueue[T]) Enqueue ¶
func (q *SyncQueue[T]) Enqueue(values ...T)
Enqueue appends one or more values to the end of the buffer. If necessary, the buffer is resized to accommodate the new values.
func (*SyncQueue[T]) Equals ¶
Equals compares the lenght and elements in the Queue to the other Queue.