ListLike

package
v0.2.27 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrEmptyList

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

func NewErrEmptyList

func NewErrEmptyList[T any](list ListLike[T]) *ErrEmptyList[T]

func (*ErrEmptyList[T]) Error

func (e *ErrEmptyList[T]) Error() string

type ErrFullList

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

func NewErrFullList

func NewErrFullList[T any](list ListLike[T]) *ErrFullList[T]

func (*ErrFullList[T]) Error

func (e *ErrFullList[T]) Error() string

type LimitedSafeList

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

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

func NewLimitedSafeList

func NewLimitedSafeList[T any](values ...T) *LimitedSafeList[T]

NewLimitedSafeList is a function that creates and returns a new instance of a LimitedSafeList.

Parameters:

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

Returns:

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

func (*LimitedSafeList[T]) Append

func (list *LimitedSafeList[T]) Append(value T) error

Append is a method of the LimitedSafeList type. It is used to add an element to the end of the list.

Panics with an error of type *ErrCallFailed if the list is fu

Parameters:

  • value: The value of type T to be added to the list.

func (*LimitedSafeList[T]) Capacity

func (list *LimitedSafeList[T]) Capacity() (int, bool)

Capacity is a method of the LimitedSafeList type. It returns the maximum number of elements that the list can hold.

Returns:

  • optional.Int: An optional integer that represents the maximum number of elements the list can hold.

func (*LimitedSafeList[T]) Clear

func (list *LimitedSafeList[T]) Clear()

Clear is a method of the LimitedSafeList type. It is used to remove all elements from the list.

func (*LimitedSafeList[T]) Copy

func (list *LimitedSafeList[T]) Copy() itff.Copier

Copy is a method of the LimitedSafeList type. It is used to create a shallow copy of the list.

Returns:

  • itff.Copier: A copy of the list.

func (*LimitedSafeList[T]) CutNilValues

func (list *LimitedSafeList[T]) CutNilValues()

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

func (*LimitedSafeList[T]) DeleteFirst

func (list *LimitedSafeList[T]) DeleteFirst() (T, error)

DeleteFirst is a method of the LimitedSafeList type. It is used to remove and return the first element from the list.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The first element in the list.

func (*LimitedSafeList[T]) DeleteLast

func (list *LimitedSafeList[T]) DeleteLast() (T, error)

DeleteLast is a method of the LimitedSafeList type. It is used to remove and return the last element from the list.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The last element in the list.

func (*LimitedSafeList[T]) IsEmpty

func (list *LimitedSafeList[T]) IsEmpty() bool

IsEmpty is a method of the LimitedSafeList type. It checks if the list is empty.

Returns:

  • bool: A boolean value that is true if the list is empty, and false otherwise.

func (*LimitedSafeList[T]) IsFull

func (list *LimitedSafeList[T]) IsFull() (isFull bool)

IsFull is a method of the LimitedSafeList type. It checks if the list is fu

Returns:

  • isFull: A boolean value that is true if the list is full, and false otherwise.

func (*LimitedSafeList[T]) Iterator

func (list *LimitedSafeList[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedSafeList type. It is used to return an iterator for the list. However, the iterator does not share the list's thread safety.

Returns:

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

func (*LimitedSafeList[T]) PeekFirst

func (list *LimitedSafeList[T]) PeekFirst() (T, error)

PeekFirst is a method of the LimitedSafeList type. It is used to return the first element from the list without removing it.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The first element in the list.

func (*LimitedSafeList[T]) PeekLast

func (list *LimitedSafeList[T]) PeekLast() (T, error)

PeekLast is a method of the LimitedSafeList type. It is used to return the last element from the list without removing it.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The last element in the list.

func (*LimitedSafeList[T]) Prepend

func (list *LimitedSafeList[T]) Prepend(value T) error

Prepend is a method of the LimitedSafeList type. It is used to add an element to the front of the list.

Panics with an error of type *ErrCallFailed if the list is fu

Parameters:

  • value: The value of type T to be added to the list.

func (*LimitedSafeList[T]) Size

func (list *LimitedSafeList[T]) Size() int

Size is a method of the LimitedSafeList type. It returns the number of elements in the list.

Returns:

  • int: An integer that represents the number of elements in the list.

func (*LimitedSafeList[T]) Slice

func (list *LimitedSafeList[T]) Slice() []T

Slice is a method of the LimitedSafeList type. It is used to return a slice of the elements in the list.

Returns:

  • []T: A slice of type T containing the elements of the list.

func (*LimitedSafeList[T]) String

func (list *LimitedSafeList[T]) String() string

String is a method of the LimitedSafeList type. It returns a string representation of the list including information about its size, capacity, and elements.

Returns:

  • string: A string representation of the list.

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

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

Parameters:

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

Return:

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

func (*LimitedSafeQueue[T]) Capacity

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

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

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

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

func (*LimitedSafeQueue[T]) Copy

func (queue *LimitedSafeQueue[T]) Copy() itff.Copier

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

Returns:

  • itf.Copier: A copy of the queue.

func (*LimitedSafeQueue[T]) CutNilValues

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

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

func (*LimitedSafeQueue[T]) Dequeue

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

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

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

Enqueue is a method of the LimitedSafeQueue 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 fu

Parameters:

  • value: The value of type T to be added to the queue.

func (*LimitedSafeQueue[T]) IsEmpty

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

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

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

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

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

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

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

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

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

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

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

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

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

String is a method of the LimitedSafeQueue type. It returns a string representation of the queue, including its size, capacity, and the elements it contains.

type ListLike

type ListLike[T any] interface {
	// The IsEmpty method checks if the list is empty and returns a boolean value
	// indicating whether it is empty or not.
	IsEmpty() bool

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

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

	// The String method returns a string representation of the list.
	// It is useful for debugging and logging purposes.
	fmt.Stringer

	// CutNilValues is a method that removes all nil values from the list.
	// It is useful for cleaning up the list and removing any empty or nil elements.
	CutNilValues()

	// The itf.Iterable interface is used to provide an iterator for the list.
	itf.Iterable[T]

	// The itf.Slicer interface is used to provide a slicer for the list.
	itff.Slicer[T]

	// The itf.Copier interface is used to provide a method for copying the list.
	itff.Copier
}

type SafeList

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

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

func NewSafeList

func NewSafeList[T any](values ...T) *SafeList[T]

NewSafeList is a function that creates and returns a new instance of a SafeList.

Parameters:

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

Returns:

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

func (*SafeList[T]) Append

func (list *SafeList[T]) Append(value T)

Append is a method of the SafeList type. It is used to add an element to the end of the list.

Panics with an error of type *ErrCallFailed if the list is fu

Parameters:

  • value: The value of type T to be added to the list.

func (*SafeList[T]) Capacity

func (list *SafeList[T]) Capacity() (int, bool)

Capacity is a method of the SafeList type. It returns the maximum number of elements that the list can hold.

Returns:

  • optional.Int: An optional integer that represents the maximum number of elements the list can hold.

func (*SafeList[T]) Clear

func (list *SafeList[T]) Clear()

Clear is a method of the SafeList type. It is used to remove all elements from the list.

func (*SafeList[T]) Copy

func (list *SafeList[T]) Copy() itff.Copier

Copy is a method of the SafeList type. It is used to create a shallow copy of the list.

Returns:

  • itf.Copier: A copy of the list.

func (*SafeList[T]) CutNilValues

func (list *SafeList[T]) CutNilValues()

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

func (*SafeList[T]) DeleteFirst

func (list *SafeList[T]) DeleteFirst() (T, error)

DeleteFirst is a method of the SafeList type. It is used to remove and return the first element from the list.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The first element in the list.

func (*SafeList[T]) DeleteLast

func (list *SafeList[T]) DeleteLast() (T, error)

DeleteLast is a method of the SafeList type. It is used to remove and return the last element from the list.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The last element in the list.

func (*SafeList[T]) IsEmpty

func (list *SafeList[T]) IsEmpty() bool

IsEmpty is a method of the SafeList type. It checks if the list is empty.

Returns:

  • bool: A boolean value that is true if the list is empty, and false otherwise.

func (*SafeList[T]) IsFull

func (list *SafeList[T]) IsFull() bool

IsFull is a method of the SafeList type. It checks if the list is fu

Returns:

  • isFull: A boolean value that is true if the list is full, and false otherwise.

func (*SafeList[T]) Iterator

func (list *SafeList[T]) Iterator() itf.Iterater[T]

Iterator is a method of the SafeList type. It is used to return an iterator for the list. However, the iterator does not share the list's thread safety.

Returns:

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

func (*SafeList[T]) PeekFirst

func (list *SafeList[T]) PeekFirst() (T, error)

PeekFirst is a method of the SafeList type. It is used to return the first element from the list without removing it.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The first element in the list.

func (*SafeList[T]) PeekLast

func (list *SafeList[T]) PeekLast() (T, error)

PeekLast is a method of the SafeList type. It is used to return the last element from the list without removing it.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The last element in the list.

func (*SafeList[T]) Prepend

func (list *SafeList[T]) Prepend(value T)

Prepend is a method of the SafeList type. It is used to add an element to the front of the list.

Panics with an error of type *ErrCallFailed if the list is fu

Parameters:

  • value: The value of type T to be added to the list.

func (*SafeList[T]) Size

func (list *SafeList[T]) Size() int

Size is a method of the SafeList type. It returns the number of elements in the list.

Returns:

  • int: An integer that represents the number of elements in the list.

func (*SafeList[T]) Slice

func (list *SafeList[T]) Slice() []T

Slice is a method of the SafeList type. It is used to return a slice of the elements in the list.

Returns:

  • []T: A slice of type T containing the elements of the list.

func (*SafeList[T]) String

func (list *SafeList[T]) String() string

String is a method of the SafeList type. It returns a string representation of the list including information about its size, capacity, and elements.

Returns:

  • string: A string representation of the list.

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

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]) 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

func (queue *SafeQueue[T]) Copy() itff.Copier

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

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

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

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

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 fu

Parameters:

  • value: The value of type T to be added to the queue.

func (*SafeQueue[T]) IsEmpty

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

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]) Iterator

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

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

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

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

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

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

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

func (queue *SafeQueue[T]) String() 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.

Jump to

Keyboard shortcuts

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