Documentation ¶
Overview ¶
Package ListLike provides a Queuer interface that defines methods for a queue data structure.
Index ¶
- type ArrayQueue
- func (queue *ArrayQueue[T]) Capacity() optional.Int
- func (queue *ArrayQueue[T]) Clear()
- func (queue *ArrayQueue[T]) Copy() itf.Copier
- func (queue *ArrayQueue[T]) CutNilValues()
- func (queue *ArrayQueue[T]) Dequeue() (T, error)
- func (queue *ArrayQueue[T]) Enqueue(value T) error
- func (queue *ArrayQueue[T]) IsEmpty() bool
- func (queue *ArrayQueue[T]) IsFull() (isFull bool)
- func (queue *ArrayQueue[T]) Iterator() itf.Iterater[T]
- func (queue *ArrayQueue[T]) Peek() (T, error)
- func (queue *ArrayQueue[T]) Size() int
- func (queue *ArrayQueue[T]) Slice() []T
- func (queue *ArrayQueue[T]) String() string
- func (queue *ArrayQueue[T]) WithCapacity(capacity int) (Queuer[T], error)
- type ErrEmptyQueue
- type ErrFullQueue
- type LinkedQueue
- func (queue *LinkedQueue[T]) Capacity() optional.Int
- func (queue *LinkedQueue[T]) Clear()
- func (queue *LinkedQueue[T]) Copy() itf.Copier
- func (queue *LinkedQueue[T]) CutNilValues()
- func (queue *LinkedQueue[T]) Dequeue() (T, error)
- func (queue *LinkedQueue[T]) Enqueue(value T) error
- func (queue *LinkedQueue[T]) IsEmpty() bool
- func (queue *LinkedQueue[T]) IsFull() (isFull bool)
- func (queue *LinkedQueue[T]) Iterator() itf.Iterater[T]
- func (queue *LinkedQueue[T]) Peek() (T, error)
- func (queue *LinkedQueue[T]) Size() int
- func (queue *LinkedQueue[T]) Slice() []T
- func (queue *LinkedQueue[T]) String() string
- func (queue *LinkedQueue[T]) WithCapacity(capacity int) (Queuer[T], error)
- type Queuer
- type SafeQueue
- func (queue *SafeQueue[T]) Capacity() optional.Int
- func (queue *SafeQueue[T]) Clear()
- func (queue *SafeQueue[T]) Copy() itf.Copier
- func (queue *SafeQueue[T]) CutNilValues()
- func (queue *SafeQueue[T]) Dequeue() (T, error)
- func (queue *SafeQueue[T]) Enqueue(value T) error
- func (queue *SafeQueue[T]) IsEmpty() bool
- func (queue *SafeQueue[T]) IsFull() (isFull bool)
- func (queue *SafeQueue[T]) Iterator() itf.Iterater[T]
- func (queue *SafeQueue[T]) Peek() (T, error)
- func (queue *SafeQueue[T]) Size() int
- func (queue *SafeQueue[T]) Slice() []T
- func (queue *SafeQueue[T]) String() string
- func (queue *SafeQueue[T]) WithCapacity(capacity int) (Queuer[T], error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayQueue ¶
type ArrayQueue[T any] struct { // contains filtered or unexported fields }
ArrayQueue is a generic type that represents a queue data structure with or without a limited capacity. It is implemented using an array.
func NewArrayQueue ¶
func NewArrayQueue[T any](values ...T) *ArrayQueue[T]
NewArrayQueue is a function that creates and returns a new instance of a ArrayQueue.
Parameters:
- values: A variadic parameter of type T, which represents the initial values to be stored in the queue.
Returns:
- *ArrayQueue[T]: A pointer to the newly created ArrayQueue.
func (*ArrayQueue[T]) Capacity ¶
func (queue *ArrayQueue[T]) Capacity() optional.Int
Capacity is a method of the ArrayQueue type. It is used to return the maximum number of elements the queue can hold.
Returns:
- optional.Int: An optional integer that represents the maximum number of elements the queue can hold.
func (*ArrayQueue[T]) Clear ¶
func (queue *ArrayQueue[T]) Clear()
Clear is a method of the ArrayQueue type. It is used to remove all the elements from the queue, making it empty.
func (*ArrayQueue[T]) Copy ¶ added in v0.2.15
func (queue *ArrayQueue[T]) Copy() itf.Copier
Copy is a method of the ArrayQueue type. It is used to create a shallow copy of the queue.
Returns:
- itf.Copier: A copy of the queue.
func (*ArrayQueue[T]) CutNilValues ¶
func (queue *ArrayQueue[T]) CutNilValues()
CutNilValues is a method of the ArrayQueue type. It is used to remove all nil values from the queue.
func (*ArrayQueue[T]) Dequeue ¶
func (queue *ArrayQueue[T]) Dequeue() (T, error)
Dequeue is a method of the ArrayQueue type. It is used to remove and return the element at the front of the queue.
Panics with an error of type *ErrCallFailed if the queue is empty.
Returns:
- T: The element at the front of the queue.
func (*ArrayQueue[T]) Enqueue ¶
func (queue *ArrayQueue[T]) Enqueue(value T) error
Enqueue is a method of the ArrayQueue type. It is used to add an element to the end of the queue.
Panics with an error of type *ErrCallFailed if the queue is full.
Parameters:
- value: The value of type T to be added to the queue.
func (*ArrayQueue[T]) IsEmpty ¶
func (queue *ArrayQueue[T]) IsEmpty() bool
IsEmpty is a method of the ArrayQueue type. It is used to check if the queue is empty.
Returns:
- bool: A boolean value that is true if the queue is empty, and false otherwise.
func (*ArrayQueue[T]) IsFull ¶
func (queue *ArrayQueue[T]) IsFull() (isFull bool)
IsFull is a method of the ArrayQueue type. It is used to check if the queue is full.
Returns:
- isFull: A boolean value that is true if the queue is full, and false otherwise.
func (*ArrayQueue[T]) Iterator ¶
func (queue *ArrayQueue[T]) Iterator() itf.Iterater[T]
Iterator is a method of the ArrayQueue type. It is used to return an iterator that can be used to iterate over the elements in the queue.
Returns:
- itf.Iterater[T]: An iterator that can be used to iterate over the elements in the queue.
func (*ArrayQueue[T]) Peek ¶
func (queue *ArrayQueue[T]) Peek() (T, error)
Peek is a method of the ArrayQueue type. It is used to return the element at the front of the queue without removing it.
Panics with an error of type *ErrCallFailed if the queue is empty.
Returns:
- T: The element at the front of the queue.
func (*ArrayQueue[T]) Size ¶
func (queue *ArrayQueue[T]) Size() int
Size is a method of the ArrayQueue type. It is used to return the number of elements in the queue.
Returns:
- int: An integer that represents the number of elements in the queue.
func (*ArrayQueue[T]) Slice ¶ added in v0.2.10
func (queue *ArrayQueue[T]) Slice() []T
Slice is a method of the ArrayQueue type. It is used to return a slice of the elements in the queue.
Returns:
- []T: A slice of the elements in the queue.
func (*ArrayQueue[T]) String ¶
func (queue *ArrayQueue[T]) String() string
String is a method of the ArrayQueue type. It returns a string representation of the queue, including its capacity and the elements it contains.
Returns:
- string: A string representation of the queue.
func (*ArrayQueue[T]) WithCapacity ¶
func (queue *ArrayQueue[T]) WithCapacity(capacity int) (Queuer[T], error)
WithCapacity is a method of the ArrayList type. It is used to set the maximum number of elements the list can hold.
Panics with an error of type *ErrCallFailed if the capacity is already set, or with an error of type *ErrInvalidParameter if the provided capacity is negative or less than the current number of elements in the list.
Parameters:
- capacity: An integer that represents the maximum number of elements the list can hold.
Returns:
- Queuer[T]: A pointer to the list.
type ErrEmptyQueue ¶
type ErrEmptyQueue struct {
// contains filtered or unexported fields
}
ErrEmptyQueue is a struct that represents an error when attempting to perform a queue operation on an empty queue.
func NewErrEmptyQueue ¶
func NewErrEmptyQueue[T any](queue Queuer[T]) *ErrEmptyQueue
NewErrEmptyQueue creates a new ErrEmptyQueue.
Parameters:
- queue: the type of queue that caused the error.
Returns:
- *ErrEmptyQueue: a pointer to the new ErrEmptyQueue.
func (*ErrEmptyQueue) Error ¶
func (e *ErrEmptyQueue) Error() string
Error is a method of the ErrEmptyQueue type that implements the error interface. It returns a string representation of the error.
Returns:
- string: a string representation of the error.
type ErrFullQueue ¶
type ErrFullQueue struct {
// contains filtered or unexported fields
}
ErrFullQueue is a struct that represents an error when attempting to enqueue an element into a full queue.
func NewErrFullQueue ¶
func NewErrFullQueue[T any](queue Queuer[T]) *ErrFullQueue
NewErrFullQueue creates a new ErrFullQueue.
Parameters:
- queue: the type of queue that caused the error.
Returns:
- *ErrFullQueue: a pointer to the new ErrFullQueue.
func (*ErrFullQueue) Error ¶
func (e *ErrFullQueue) Error() string
Error is a method of the ErrFullQueue type that implements the error interface. It returns a string representation of the error.
Returns:
- string: a string representation of the error.
type LinkedQueue ¶
type LinkedQueue[T any] struct { // contains filtered or unexported fields }
LinkedQueue is a generic type that represents a queue data structure with or without a limited capacity, implemented using a linked list.
func NewLinkedQueue ¶
func NewLinkedQueue[T any](values ...T) *LinkedQueue[T]
NewLinkedQueue is a function that creates and returns a new instance of a LinkedQueue.
Parameters:
- values: A variadic parameter of type T, which represents the initial values to be stored in the queue.
Returns:
- *LinkedQueue[T]: A pointer to the newly created LinkedQueue.
func (*LinkedQueue[T]) Capacity ¶
func (queue *LinkedQueue[T]) Capacity() optional.Int
func (*LinkedQueue[T]) Clear ¶
func (queue *LinkedQueue[T]) Clear()
Clear is a method of the LinkedQueue type. It is used to remove all elements from the queue.
func (*LinkedQueue[T]) Copy ¶ added in v0.2.15
func (queue *LinkedQueue[T]) Copy() itf.Copier
Copy is a method of the LinkedQueue type. It is used to create a shallow copy of the queue.
Returns:
- itf.Copier: A copy of the queue.
func (*LinkedQueue[T]) CutNilValues ¶
func (queue *LinkedQueue[T]) CutNilValues()
CutNilValues is a method of the LinkedQueue type. It is used to remove all nil values from the queue.
func (*LinkedQueue[T]) Dequeue ¶
func (queue *LinkedQueue[T]) Dequeue() (T, error)
Dequeue is a method of the LinkedQueue type. It is used to remove and return the element at the front of the queue.
Panics with an error of type *ErrCallFailed if the queue is empty.
Returns:
- T: The value of the element at the front of the queue.
func (*LinkedQueue[T]) Enqueue ¶
func (queue *LinkedQueue[T]) Enqueue(value T) error
Enqueue is a method of the LinkedQueue type. It is used to add an element to the end of the queue.
Panics with an error of type *ErrCallFailed if the queue is full.
Parameters:
- value: A pointer to a value of type T, which is the element to be added to the queue.
func (*LinkedQueue[T]) IsEmpty ¶
func (queue *LinkedQueue[T]) IsEmpty() bool
IsEmpty is a method of the LinkedQueue type. It is used to check if the queue is empty.
Returns:
- bool: A boolean value indicating whether the queue is empty.
func (*LinkedQueue[T]) IsFull ¶
func (queue *LinkedQueue[T]) IsFull() (isFull bool)
IsFull is a method of the LinkedQueue type. It is used to check if the queue is full.
Returns:
- isFull: A boolean value indicating whether the queue is full.
func (*LinkedQueue[T]) Iterator ¶
func (queue *LinkedQueue[T]) Iterator() itf.Iterater[T]
Iterator is a method of the LinkedQueue type. It is used to return an iterator for the queue.
Returns:
- itf.Iterater[T]: An iterator for the queue.
func (*LinkedQueue[T]) Peek ¶
func (queue *LinkedQueue[T]) Peek() (T, error)
Peek is a method of the LinkedQueue type. It is used to return the element at the front of the queue without removing it.
Panics with an error of type *ErrCallFailed if the queue is empty.
Returns:
- T: The value of the element at the front of the queue.
func (*LinkedQueue[T]) Size ¶
func (queue *LinkedQueue[T]) Size() int
Size is a method of the LinkedQueue type. It is used to return the current number of elements in the queue.
Returns:
- int: An integer representing the current number of elements in the queue.
func (*LinkedQueue[T]) Slice ¶ added in v0.2.10
func (queue *LinkedQueue[T]) Slice() []T
Slice is a method of the LinkedQueue type. It is used to return a slice of the elements in the queue.
Returns:
- []T: A slice of the elements in the queue.
func (*LinkedQueue[T]) String ¶
func (queue *LinkedQueue[T]) String() string
String is a method of the LinkedQueue type. It is used to return a string representation of the queue including its size, capacity, and elements.
Returns:
- string: A string representation of the queue.
func (*LinkedQueue[T]) WithCapacity ¶
func (queue *LinkedQueue[T]) WithCapacity(capacity int) (Queuer[T], error)
WithCapacity is a method of the LinkedQueue type. It is used to set the maximum number of elements the queue can hold.
Panics with an error of type *ErrCallFailed if the capacity is already set, or with an error of type *ErrInvalidParameter if the provided capacity is negative or less than the current number of elements in the queue.
Parameters:
- capacity: An integer that represents the maximum number of elements the queue can hold.
Returns:
- Queuer[T]: A pointer to the queue with the new capacity set.
type Queuer ¶
type Queuer[T any] interface { // The Enqueue method adds a value of type T to the end of the queue. // If the queue is full, it will panic. Enqueue(value T) error // The Dequeue method is a convenience method that dequeues an element from the // queue and returns it. // If the queue is empty, it will panic. Dequeue() (T, error) // Peek is a method that returns the value at the front of the queue without // removing it. // If the queue is empty, it will panic. Peek() (T, error) // WithCapacity is a special function that modifies an existing queue data // structure to have a specific capacity. Panics if the list already has a capacity // set or if the new capacity is less than the current size of the list-like data // structure. // // As a result, it is recommended to use this function only when creating a new // list-like data structure. WithCapacity(int) (Queuer[T], error) // ListLike.ListLike[T] is an interface that defines methods for a queue data structure. ListLike.ListLike[T] }
Queuer is an interface that defines methods for a queue data structure.
type SafeQueue ¶
type SafeQueue[T any] struct { // contains filtered or unexported fields }
SafeQueue is a generic type that represents a thread-safe queue data structure with or without a limited capacity, implemented using a linked list.
func NewSafeQueue ¶
NewSafeQueue is a function that creates and returns a new instance of a SafeQueue.
Parameters:
- values: A variadic parameter of type T, which represents the initial values to be stored in the queue.
Return:
- *SafeQueue[T]: A pointer to the newly created SafeQueue.
func (*SafeQueue[T]) Capacity ¶
Capacity is a method of the SafeQueue type. It is used to return the maximum number of elements the queue can hold.
Returns:
- optional.Int: An optional integer that represents the maximum number of elements the queue can hold.
func (*SafeQueue[T]) Clear ¶
func (queue *SafeQueue[T]) Clear()
Clear is a method of the SafeQueue type. It is used to remove all elements from the queue, making it empty.
func (*SafeQueue[T]) Copy ¶ added in v0.2.15
Copy is a method of the SafeQueue type. It is used to create a shallow copy of the queue.
Returns:
- itf.Copier: A copy of the queue.
func (*SafeQueue[T]) CutNilValues ¶
func (queue *SafeQueue[T]) CutNilValues()
CutNilValues is a method of the SafeQueue type. It is used to remove all nil values from the queue.
func (*SafeQueue[T]) Dequeue ¶
Dequeue is a method of the SafeQueue type. It is used to remove and return the element at the front of the queue.
Panics with an error of type *ErrCallFailed if the queue is empty.
Returns:
- T: The value of the element at the front of the queue.
func (*SafeQueue[T]) Enqueue ¶
Enqueue is a method of the SafeQueue type. It is used to add an element to the back of the queue.
Panics with an error of type *ErrCallFailed if the queue is full.
Parameters:
- value: The value of type T to be added to the queue.
func (*SafeQueue[T]) IsEmpty ¶
IsEmpty is a method of the SafeQueue type. It is used to check if the queue is empty.
Returns:
- bool: A boolean value that is true if the queue is empty, and false otherwise.
func (*SafeQueue[T]) IsFull ¶
IsFull is a method of the SafeQueue type. It is used to check if the queue is full, meaning it has reached its maximum capacity and cannot accept any more elements.
Returns:
- isFull: A boolean value that is true if the queue is full, and false otherwise.
func (*SafeQueue[T]) Iterator ¶
Iterator is a method of the SafeQueue type. It is used to return an iterator that can be used to iterate over the elements in the queue. However, the iterator does not share the queue's thread-safety.
Returns:
- itf.Iterater[T]: An iterator that can be used to iterate over the elements in the queue.
func (*SafeQueue[T]) Peek ¶
Peek is a method of the SafeQueue type. It is used to return the element at the front of the queue without removing it.
Panics with an error of type *ErrCallFailed if the queue is empty.
Returns:
- T: The value of the element at the front of the queue.
func (*SafeQueue[T]) Size ¶
Size is a method of the SafeQueue type. It is used to return the number of elements in the queue.
Returns:
- int: An integer that represents the number of elements in the queue.
func (*SafeQueue[T]) Slice ¶ added in v0.2.10
func (queue *SafeQueue[T]) Slice() []T
Slice is a method of the SafeQueue type. It is used to return a slice of the elements in the queue.
Returns:
- []T: A slice of the elements in the queue.
func (*SafeQueue[T]) String ¶
String is a method of the SafeQueue type. It returns a string representation of the queue, including its size, capacity, and the elements it contains.
func (*SafeQueue[T]) WithCapacity ¶
WithCapacity is a method of the SafeQueue type. It is used to set the maximum number of elements the queue can hold.
Panics with an error of type *ErrCallFailed if the capacity is already set, or with an error of type *ErrInvalidParameter if the provided capacity is negative or less than the current number of elements in the queue.
Parameters:
- capacity: An integer value that represents the maximum number of elements the queue can hold.
Returns:
- Queuer[T]: A pointer to the queue with the new capacity set.