ListLike

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ListLike provides a Queuer interface that defines methods for a queue data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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](values ...T) *LimitedArrayQueue[T]

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

Parameters:

  • values: A variadic parameter of type T, which represents the initial values to be stored in the queue.

Returns:

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

func (*LimitedArrayQueue[T]) Capacity

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

Capacity is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) Clear

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

Clear is a method of the LimitedArrayQueue type. It is used to remove all the elements from the queue, making it empty.

func (*LimitedArrayQueue[T]) Copy

func (queue *LimitedArrayQueue[T]) Copy() itf.Copier

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

Returns:

  • itf.Copier: A copy of the queue.

func (*LimitedArrayQueue[T]) CutNilValues

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

CutNilValues is a method of the LimitedArrayQueue type. It is used to remove all nil values from the queue.

func (*LimitedArrayQueue[T]) Dequeue

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

Dequeue is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) Enqueue

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

Enqueue is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) IsEmpty

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

IsEmpty is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) IsFull

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

IsFull is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) Iterator

func (queue *LimitedArrayQueue[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) Peek

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

Peek is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) Size

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

Size is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) Slice

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

Slice is a method of the LimitedArrayQueue 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 (*LimitedArrayQueue[T]) String

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

String is a method of the LimitedArrayQueue 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.

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](values ...T) *LimitedLinkedQueue[T]

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

Parameters:

  • values: A variadic parameter of type T, which represents the initial values to be stored in the queue.

Returns:

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

func (*LimitedLinkedQueue[T]) Capacity

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

func (*LimitedLinkedQueue[T]) Clear

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

Clear is a method of the LimitedLinkedQueue type. It is used to remove all elements from the queue.

func (*LimitedLinkedQueue[T]) Copy

func (queue *LimitedLinkedQueue[T]) Copy() itf.Copier

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

Returns:

  • itf.Copier: A copy of the queue.

func (*LimitedLinkedQueue[T]) CutNilValues

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

CutNilValues is a method of the LimitedLinkedQueue type. It is used to remove all nil values from the queue.

func (*LimitedLinkedQueue[T]) Dequeue

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

Dequeue is a method of the LimitedLinkedQueue 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 (*LimitedLinkedQueue[T]) Enqueue

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

Enqueue is a method of the LimitedLinkedQueue 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 (*LimitedLinkedQueue[T]) IsEmpty

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

IsEmpty is a method of the LimitedLinkedQueue type. It is used to check if the queue is empty.

Returns:

  • bool: A boolean value indicating whether the queue is empty.

func (*LimitedLinkedQueue[T]) IsFull

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

IsFull is a method of the LimitedLinkedQueue type. It is used to check if the queue is full.

Returns:

  • isFull: A boolean value indicating whether the queue is full.

func (*LimitedLinkedQueue[T]) Iterator

func (queue *LimitedLinkedQueue[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedLinkedQueue type. It is used to return an iterator for the queue.

Returns:

  • itf.Iterater[T]: An iterator for the queue.

func (*LimitedLinkedQueue[T]) Peek

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

Peek is a method of the LimitedLinkedQueue 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 (*LimitedLinkedQueue[T]) Size

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

Size is a method of the LimitedLinkedQueue 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 (*LimitedLinkedQueue[T]) Slice

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

Slice is a method of the LimitedLinkedQueue 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 (*LimitedLinkedQueue[T]) String

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

String is a method of the LimitedLinkedQueue 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.

type LimitedQueuer

type LimitedQueuer[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)

	// ListLike.ListLike[T] is an interface that defines methods for a queue data structure.
	ListLike.ListLike[T]

	// The Capacity method returns the maximum number of elements that the list can hold.
	Capacity() (int, bool)

	// The IsFull method checks if the list is full, meaning it has reached its maximum
	// capacity and cannot accept any more elements.
	IsFull() bool
}

Queuer is an interface that defines methods for a queue data structure.

Jump to

Keyboard shortcuts

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