Common

package
v0.2.33 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 3 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 ListLike

type ListLike[T any] interface {
	// 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

	// 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()

	itf.Iterable[T]

	itff.Slicer[T]

	itff.Copier

	fmt.Stringer
}

ListLike is an interface that defines methods for a list data structure.

type ListNode

type ListNode[T any] struct {
	// The Value stored in the node.
	Value T
	// contains filtered or unexported fields
}

ListNode represents a node in a linked list. It holds a value of a generic type and a reference to the next node in the list.

func NewListNode

func NewListNode[T any](value T) ListNode[T]

NewListNode creates a new LinkedNode with the given value.

func (*ListNode[T]) Next

func (node *ListNode[T]) Next() *ListNode[T]

func (*ListNode[T]) Prev

func (node *ListNode[T]) Prev() *ListNode[T]

func (*ListNode[T]) SetNext

func (node *ListNode[T]) SetNext(next *ListNode[T])

func (*ListNode[T]) SetPrev

func (node *ListNode[T]) SetPrev(prev *ListNode[T])

type ListSafeNode

type ListSafeNode[T any] struct {
	// The Value stored in the node.
	Value T
	// contains filtered or unexported fields
}

ListSafeNode represents a node in a linked list. It holds a value of a generic type and a reference to the next and previous nodes in the list.

func NewListSafeNode

func NewListSafeNode[T any](value T) ListSafeNode[T]

NewListSafeNode creates a new ListSafeNode with the given value.

func (*ListSafeNode[T]) Next

func (node *ListSafeNode[T]) Next() *ListSafeNode[T]

Next returns the next node in the list.

func (*ListSafeNode[T]) Prev

func (node *ListSafeNode[T]) Prev() *ListSafeNode[T]

Prev returns the previous node in the list.

func (*ListSafeNode[T]) SetNext

func (node *ListSafeNode[T]) SetNext(next *ListSafeNode[T])

SetNext sets the next node in the list.

func (*ListSafeNode[T]) SetPrev

func (node *ListSafeNode[T]) SetPrev(prev *ListSafeNode[T])

SetPrev sets the previous node in the list.

type Lister

type Lister[T any] interface {
	// Append is a method that adds a value of type T to the end of the list.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the list.
	//
	// Returns:
	//
	//   - error: An error if the list is full.
	Append(value T) error

	// DeleteFirst is a method that deletes an element from the front of the list and
	// returns it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was deleted.
	DeleteFirst() T

	// PeekFirst is a method that returns the value at the front of the list without
	// removing it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T at the front of the list.
	PeekFirst() T

	// Prepend is a method that adds a value of type T to the end of the list.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the list.
	//
	// Returns:
	//
	//   - error: An error if the list is full.
	Prepend(value T) error

	// DeleteLast is a method that deletes an element from the end of the list and
	// returns it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was deleted.
	DeleteLast() T

	// PeekLast is a method that returns the value at the end of the list without
	// removing it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T at the end of the list.
	PeekLast() T

	ListLike[T]
}

Lister is an interface that defines methods for a list data structure.

type QueueNode

type QueueNode[T any] struct {
	// Value is the value stored in the node.
	Value T
	// contains filtered or unexported fields
}

QueueNode represents a node in a linked list.

func NewQueueNode

func NewQueueNode[T any](value T) QueueNode[T]

NewQueueNode creates a new LinkedNode with the given value.

func (*QueueNode[T]) Next

func (node *QueueNode[T]) Next() *QueueNode[T]

func (*QueueNode[T]) SetNext

func (node *QueueNode[T]) SetNext(next *QueueNode[T])

type QueueSafeNode

type QueueSafeNode[T any] struct {
	// Value is the Value stored in the node.
	Value T
	// contains filtered or unexported fields
}

QueueSafeNode represents a node in a linked list.

func NewQueueSafeNode

func NewQueueSafeNode[T any](value T) QueueSafeNode[T]

NewQueueSafeNode creates a new QueueSafeNode with the given value.

func (*QueueSafeNode[T]) Next

func (node *QueueSafeNode[T]) Next() *QueueSafeNode[T]

Next returns the next node in the list.

func (*QueueSafeNode[T]) SetNext

func (node *QueueSafeNode[T]) SetNext(next *QueueSafeNode[T])

SetNext sets the next node in the list.

type Queuer

type Queuer[T any] interface {
	// Enqueue is a method that adds a value of type T to the end of the queue.
	// If the queue is full, it will panic.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the queue.
	Enqueue(value T)

	// Dequeue is a method that dequeues an element from the queue and returns it.
	// If the queue is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was dequeued.
	Dequeue() T

	// 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.
	//
	// Returns:
	//
	//   - T: The value of type T at the front of the queue.
	Peek() T

	ListLike[T]
}

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

type SafeLister

type SafeLister[T any] interface {
	// Append is a method that adds a value of type T to the end of the list.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the list.
	//
	// Returns:
	//
	//   - error: An error if the list is full.
	Append(value T) error

	// DeleteFirst is a method that deletes an element from the front of the list and
	// returns it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was deleted.
	DeleteFirst() (T, error)

	// PeekFirst is a method that returns the value at the front of the list without
	// removing it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T at the front of the list.
	PeekFirst() (T, error)

	// Prepend is a method that adds a value of type T to the end of the list.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the list.
	//
	// Returns:
	//
	//   - error: An error if the list is full.
	Prepend(value T) error

	// DeleteLast is a method that deletes an element from the end of the list and
	// returns it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was deleted.
	DeleteLast() (T, error)

	// PeekLast is a method that returns the value at the end of the list without
	// removing it. If the list is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T at the end of the list.
	PeekLast() (T, error)

	ListLike[T]
}

Lister is an interface that defines methods for a list data structure.

type SafeQueuer

type SafeQueuer[T any] interface {
	// Enqueue is a method that adds a value of type T to the end of the queue.
	// If the queue is full, it will panic.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the queue.
	Enqueue(value T) error

	// Dequeue is a method that dequeues an element from the queue and returns it.
	// If the queue is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was dequeued.
	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.
	//
	// Returns:
	//
	//   - T: The value of type T at the front of the queue.
	Peek() (T, error)

	ListLike[T]
}

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

type StackNode

type StackNode[T any] struct {
	// value is the value stored in the node.
	Value T
	// contains filtered or unexported fields
}

StackNode represents a node in a linked list.

func NewStackNode

func NewStackNode[T any](value T) StackNode[T]

func (*StackNode[T]) Next

func (node *StackNode[T]) Next() *StackNode[T]

func (*StackNode[T]) SetNext

func (node *StackNode[T]) SetNext(next *StackNode[T])

type Stacker

type Stacker[T any] interface {
	// Push is a method that adds a value of type T to the end of the stack.
	// If the stack is full, it will panic.
	//
	// Parameters:
	//
	//   - value: The value of type T to add to the stack.
	Push(value T)

	// Pop is a method that pops an element from the stack and returns it.
	// If the stack is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T that was popped.
	Pop() T

	// Peek is a method that returns the value at the front of the stack without removing
	// it.
	// If the stack is empty, it will panic.
	//
	// Returns:
	//
	//   - T: The value of type T at the front of the stack.
	Peek() T

	ListLike[T]
}

Stacker is an interface that defines methods for a stack data structure.

Jump to

Keyboard shortcuts

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