queue

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Index

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]() *ArrayQueue[T]

NewArrayQueue is a function that creates and returns a new instance of a ArrayQueue.

Returns:

  • *ArrayQueue[T]: A pointer to the newly created ArrayQueue. Never returns nil.

func (*ArrayQueue[T]) Capacity

func (queue *ArrayQueue[T]) Capacity() int

Capacity implements the Queuer interface.

func (*ArrayQueue[T]) Clear

func (queue *ArrayQueue[T]) Clear()

Clear implements the Queuer interface.

func (*ArrayQueue[T]) Copy

func (queue *ArrayQueue[T]) Copy() *ArrayQueue[T]

Copy is a method of the ArrayQueue type. It is used to create a shallow copy of the queue.

Returns:

  • *ArrayQueue[T]: A shallow copy of the queue.

func (*ArrayQueue[T]) Dequeue

func (queue *ArrayQueue[T]) Dequeue() (T, bool)

Dequeue implements the Queuer interface.

func (*ArrayQueue[T]) Enqueue

func (queue *ArrayQueue[T]) Enqueue(value T) bool

Enqueue implements the Queuer interface.

Always returns true.

func (*ArrayQueue[T]) EnqueueMany

func (queue *ArrayQueue[T]) EnqueueMany(values []T) int

EnqueueMany implements the Queuer interface.

Always returns the number of elements enqueued.

func (*ArrayQueue[T]) GoString

func (queue *ArrayQueue[T]) GoString() string

GoString implements the Queuer interface.

func (*ArrayQueue[T]) IsEmpty

func (queue *ArrayQueue[T]) IsEmpty() bool

IsEmpty implements the Queuer interface.

func (*ArrayQueue[T]) IsFull

func (queue *ArrayQueue[T]) IsFull() bool

IsFull implements the Queuer interface.

func (*ArrayQueue[T]) Peek

func (queue *ArrayQueue[T]) Peek() (T, bool)

Peek implements the Queuer interface.

func (*ArrayQueue[T]) Size

func (queue *ArrayQueue[T]) Size() int

Size implements the Queuer interface.

func (*ArrayQueue[T]) Slice

func (queue *ArrayQueue[T]) Slice() []T

Slice implements the Queuer interface.

type LimitedArrayQueue

type LimitedArrayQueue[T any] struct {
	// contains filtered or unexported fields
}

LimitedArrayQueue is a generic type that represents a queue data structure with or without a limited capacity. It is implemented using an array.

func NewLimitedArrayQueue

func NewLimitedArrayQueue[T any](capacity int) (*LimitedArrayQueue[T], error)

NewLimitedArrayQueue is a function that creates and returns a new instance of a LimitedArrayQueue.

Parameters:

  • capacity: The maximum number of elements the queue can hold.

Returns:

  • *LimitedArrayQueue[T]: A pointer to the newly created LimitedArrayQueue.
  • error: An error of type *common.ErrInvalidParameter if the capacity is less than 0.

func (*LimitedArrayQueue[T]) Capacity

func (queue *LimitedArrayQueue[T]) Capacity() int

Capacity implements the Queuer interface.

func (*LimitedArrayQueue[T]) Clear

func (queue *LimitedArrayQueue[T]) Clear()

Clear implements the Queuer interface.

func (*LimitedArrayQueue[T]) Copy

func (queue *LimitedArrayQueue[T]) Copy() *LimitedArrayQueue[T]

Copy is a method of the LimitedArrayQueue type. It is used to create a shallow copy of the queue.

Returns:

  • *LimitedArrayQueue[T]: A shallow copy of the queue.

func (*LimitedArrayQueue[T]) Dequeue

func (queue *LimitedArrayQueue[T]) Dequeue() (T, bool)

Dequeue implements the Queuer interface.

func (*LimitedArrayQueue[T]) Enqueue

func (queue *LimitedArrayQueue[T]) Enqueue(value T) bool

Enqueue implements the Queuer interface.

func (*LimitedArrayQueue[T]) EnqueueMany

func (queue *LimitedArrayQueue[T]) EnqueueMany(values []T) int

EnqueueMany implements the Queuer interface.

func (*LimitedArrayQueue[T]) GoString

func (queue *LimitedArrayQueue[T]) GoString() string

GoString implements the fmt.GoStringer interface.

func (*LimitedArrayQueue[T]) IsEmpty

func (queue *LimitedArrayQueue[T]) IsEmpty() bool

IsEmpty implements the Queuer interface.

func (*LimitedArrayQueue[T]) IsFull

func (queue *LimitedArrayQueue[T]) IsFull() bool

IsFull implements the Queuer interface.

func (*LimitedArrayQueue[T]) Peek

func (queue *LimitedArrayQueue[T]) Peek() (T, bool)

Peek implements the Queuer interface.

func (*LimitedArrayQueue[T]) Size

func (queue *LimitedArrayQueue[T]) Size() int

Size implements the Queuer interface.

func (*LimitedArrayQueue[T]) Slice

func (queue *LimitedArrayQueue[T]) Slice() []T

Slice implements the Queuer interface.

type LimitedLinkedQueue

type LimitedLinkedQueue[T any] struct {
	// contains filtered or unexported fields
}

LimitedLinkedQueue is a generic type that represents a queue data structure with or without a limited capacity, implemented using a linked list.

func NewLimitedLinkedQueue

func NewLimitedLinkedQueue[T any](capacity int) (*LimitedLinkedQueue[T], error)

NewLimitedLinkedQueue is a function that creates and returns a new instance of a LimitedLinkedQueue.

Parameters:

  • capacity: The maximum number of elements the queue can hold.

Returns:

  • *LimitedLinkedQueue[T]: A pointer to the newly created LimitedLinkedQueue.
  • error: An error of type *common.ErrInvalidParameter if the capacity is less than 0.

func (*LimitedLinkedQueue[T]) Capacity

func (queue *LimitedLinkedQueue[T]) Capacity() int

Capacity implements the Queuer interface.

func (*LimitedLinkedQueue[T]) Clear

func (queue *LimitedLinkedQueue[T]) Clear()

Clear implements the Queuer interface.

func (*LimitedLinkedQueue[T]) Copy

func (queue *LimitedLinkedQueue[T]) Copy() *LimitedLinkedQueue[T]

Copy is a method of the LimitedLinkedQueue type. It is used to create a shallow copy of the queue.

Returns:

  • *LimitedLinkedQueue[T]: A shallow copy of the queue.

func (*LimitedLinkedQueue[T]) Dequeue

func (queue *LimitedLinkedQueue[T]) Dequeue() (T, bool)

Dequeue implements the Queuer interface.

func (*LimitedLinkedQueue[T]) Enqueue

func (queue *LimitedLinkedQueue[T]) Enqueue(value T) bool

Enqueue implements the Queuer interface.

func (*LimitedLinkedQueue[T]) EnqueueMany

func (queue *LimitedLinkedQueue[T]) EnqueueMany(values []T) int

EnqueueMany implements the Queuer interface.

func (*LimitedLinkedQueue[T]) GoString

func (queue *LimitedLinkedQueue[T]) GoString() string

GoString implements the fmt.GoStringer interface.

func (*LimitedLinkedQueue[T]) IsEmpty

func (queue *LimitedLinkedQueue[T]) IsEmpty() bool

IsEmpty implements the Queuer interface.

func (*LimitedLinkedQueue[T]) IsFull

func (queue *LimitedLinkedQueue[T]) IsFull() bool

IsFull implements the Queuer interface.

func (*LimitedLinkedQueue[T]) Peek

func (queue *LimitedLinkedQueue[T]) Peek() (T, bool)

Peek implements the Queuer interface.

func (*LimitedLinkedQueue[T]) Size

func (queue *LimitedLinkedQueue[T]) Size() int

Size implements the Queuer interface.

func (*LimitedLinkedQueue[T]) Slice

func (queue *LimitedLinkedQueue[T]) Slice() []T

Slice implements the Queuer interface.

type LimitedSafeQueue

type LimitedSafeQueue[T any] struct {
	// contains filtered or unexported fields
}

LimitedSafeQueue is a generic type that represents a thread-safe queue data structure with or without a limited capacity, implemented using a linked list.

func NewLimitedSafeQueue

func NewLimitedSafeQueue[T any](capacity int) (*LimitedSafeQueue[T], error)

NewLimitedSafeQueue is a function that creates and returns a new instance of a LimitedSafeQueue.

Parameters:

  • capacity: The capacity of the queue.

Return:

  • *LimitedSafeQueue[T]: A pointer to the newly created LimitedSafeQueue.

func (*LimitedSafeQueue[T]) Capacity

func (queue *LimitedSafeQueue[T]) Capacity() int

Capacity implements the Queuer interface.

func (*LimitedSafeQueue[T]) Clear

func (queue *LimitedSafeQueue[T]) Clear()

Clear implements the Queuer interface.

func (*LimitedSafeQueue[T]) Copy

func (queue *LimitedSafeQueue[T]) Copy() *LimitedSafeQueue[T]

Copy is a method of the LimitedSafeQueue type. It is used to create a shallow copy of the queue.

Returns:

  • *LimitedSafeQueue[T]: A shallow copy of the queue.

func (*LimitedSafeQueue[T]) Dequeue

func (queue *LimitedSafeQueue[T]) Dequeue() (T, bool)

Dequeue implements the Queuer interface.

func (*LimitedSafeQueue[T]) Enqueue

func (queue *LimitedSafeQueue[T]) Enqueue(value T) bool

Enqueue implements the Queuer interface.

func (*LimitedSafeQueue[T]) EnqueueMany

func (queue *LimitedSafeQueue[T]) EnqueueMany(values []T) int

EnqueueMany implements the Queuer interface.

func (*LimitedSafeQueue[T]) GoString

func (queue *LimitedSafeQueue[T]) GoString() string

GoString implements the fmt.GoStringer interface.

func (*LimitedSafeQueue[T]) IsEmpty

func (queue *LimitedSafeQueue[T]) IsEmpty() bool

IsEmpty implements the Queuer interface.

func (*LimitedSafeQueue[T]) IsFull

func (queue *LimitedSafeQueue[T]) IsFull() (isFull bool)

IsFull implements the Queuer interface.

func (*LimitedSafeQueue[T]) Peek

func (queue *LimitedSafeQueue[T]) Peek() (T, bool)

Peek implements the Queuer interface.

func (*LimitedSafeQueue[T]) Size

func (queue *LimitedSafeQueue[T]) Size() int

Size implements the Queuer interface.

func (*LimitedSafeQueue[T]) Slice

func (queue *LimitedSafeQueue[T]) Slice() []T

Slice implements the Queuer interface.

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]() *LinkedQueue[T]

NewLinkedQueue is a function that creates and returns a new instance of a LinkedQueue.

Returns:

  • *LinkedQueue[T]: A pointer to the newly created LinkedQueue. Never returns nil.

func (*LinkedQueue[T]) Capacity

func (queue *LinkedQueue[T]) Capacity() int

Capacity implements the Queuer interface.

Always returns -1.

func (*LinkedQueue[T]) Clear

func (queue *LinkedQueue[T]) Clear()

Clear implements the Queuer interface.

func (*LinkedQueue[T]) Copy

func (queue *LinkedQueue[T]) Copy() *LinkedQueue[T]

Copy is a method that returns a copy of the LinkedQueue.

Returns:

  • *LinkedQueue[T]: A copy of the LinkedQueue.

func (*LinkedQueue[T]) Dequeue

func (queue *LinkedQueue[T]) Dequeue() (T, bool)

Dequeue implements the Queuer interface.

func (*LinkedQueue[T]) Enqueue

func (queue *LinkedQueue[T]) Enqueue(value T) bool

Enqueue implements the Queuer interface.

Always returns true.

func (*LinkedQueue[T]) EnqueueMany

func (queue *LinkedQueue[T]) EnqueueMany(values []T) int

EnqueueMany implements the Queuer interface.

Always returns true.

func (*LinkedQueue[T]) GoString

func (queue *LinkedQueue[T]) GoString() string

GoString implements the fmt.GoStringer interface.

func (*LinkedQueue[T]) IsEmpty

func (queue *LinkedQueue[T]) IsEmpty() bool

IsEmpty implements the Queuer interface.

func (*LinkedQueue[T]) IsFull

func (queue *LinkedQueue[T]) IsFull() bool

IsFull implements the Queuer interface.

Always returns false.

func (*LinkedQueue[T]) Peek

func (queue *LinkedQueue[T]) Peek() (T, bool)

Peek implements the Queuer interface.

func (*LinkedQueue[T]) Size

func (queue *LinkedQueue[T]) Size() int

Size implements the Queuer interface.

func (*LinkedQueue[T]) Slice

func (queue *LinkedQueue[T]) Slice() []T

Slice implements the Queuer interface.

type Queuer

type Queuer[T any] interface {
	// Enqueue is a method that adds a value of type T to the end of the queue.
	//
	// Parameters:
	//   - value: The value of type T to add to the queue.
	//
	// Returns:
	//   - bool: True if the value was successfully added to the queue, false otherwise.
	Enqueue(value T) bool

	// EnqueueMany is a method that adds multiple values of type T to the end of the queue.
	//
	// Parameters:
	//   - values: The values of type T to add to the queue.
	//
	// Returns:
	//   - int: The number of values successfully added to the queue.
	EnqueueMany(values []T) int

	// Dequeue is a method that dequeues an element from the queue and returns it.
	//
	// Returns:
	//   - T: The value of type T that was dequeued.
	//   - bool: True if the value was successfully dequeued, false otherwise.
	Dequeue() (T, bool)

	// Peek is a method that returns the value at the front of the queue without
	// removing it.
	//
	// Returns:
	//   - T: The value of type T at the front of the queue.
	//   - bool: True if the value was successfully peeked, false otherwise.
	Peek() (T, bool)

	// IsEmpty is a method that checks whether the list is empty.
	//
	// Returns:
	//
	//   - bool: True if the list is empty, false otherwise.
	IsEmpty() bool

	// Size method returns the number of elements currently in the list.
	//
	// Returns:
	//
	//   - int: The number of elements in the list.
	Size() int

	// Clear method is used to remove all elements from the list, making it empty.
	Clear()

	// Capacity is a method that returns the maximum number of elements that the list can hold.
	//
	// Returns:
	//
	//   - int: The maximum number of elements that the list can hold. -1 if there is no limit.
	Capacity() int

	// IsFull is a method that checks whether the list is full.
	//
	// Returns:
	//
	//   - bool: True if the list is full, false otherwise.
	IsFull() bool

	// Slice is a method that returns a slice of the elements in the list.
	//
	// Returns:
	//  	- []T: A slice of the elements in the list.
	Slice() []T

	fmt.GoStringer
}

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

func NewSafeQueue[T any]() *SafeQueue[T]

NewSafeQueue is a function that creates and returns a new instance of a SafeQueue.

Return:

  • *SafeQueue[T]: A pointer to the newly created SafeQueue. Never returns nil.

func (*SafeQueue[T]) Capacity

func (queue *SafeQueue[T]) Capacity() int

Capacity implements the Queuer interface.

Always returns -1.

func (*SafeQueue[T]) Clear

func (queue *SafeQueue[T]) Clear()

Clear implements the Queuer interface.

func (*SafeQueue[T]) Copy

func (queue *SafeQueue[T]) Copy() *SafeQueue[T]

Copy is a method that returns a deep copy of the queue.

Returns:

  • *SafeQueue[T]: A pointer to the newly created SafeQueue. Never returns nil.

func (*SafeQueue[T]) Dequeue

func (queue *SafeQueue[T]) Dequeue() (T, bool)

Dequeue implements the Queuer interface.

func (*SafeQueue[T]) Enqueue

func (queue *SafeQueue[T]) Enqueue(value T) bool

Enqueue implements the Queuer interface.

Always returns true.

func (*SafeQueue[T]) EnqueueMany

func (queue *SafeQueue[T]) EnqueueMany(values []T) int

Enqueue implements the Queuer interface.

Always returns true.

func (*SafeQueue[T]) GoString

func (queue *SafeQueue[T]) GoString() string

GoString implements the fmt.GoStringer interface.

func (*SafeQueue[T]) IsEmpty

func (queue *SafeQueue[T]) IsEmpty() bool

IsEmpty implements the Queuer interface.

func (*SafeQueue[T]) IsFull

func (queue *SafeQueue[T]) IsFull() bool

IsFull implements the Queuer interface.

Always returns false.

func (*SafeQueue[T]) Peek

func (queue *SafeQueue[T]) Peek() (T, bool)

Peek implements the Queuer interface.

func (*SafeQueue[T]) Size

func (queue *SafeQueue[T]) Size() int

Size implements the Queuer interface.

func (*SafeQueue[T]) Slice

func (queue *SafeQueue[T]) Slice() []T

Slice implements the Queuer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL