Base

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LimitedArrayStack

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

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

func NewLimitedArrayStack

func NewLimitedArrayStack[T any](values ...T) *LimitedArrayStack[T]

NewLimitedArrayStack is a function that creates and returns a new instance of a LimitedArrayStack.

Parameters:

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

Returns:

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

func (*LimitedArrayStack[T]) Capacity

func (stack *LimitedArrayStack[T]) Capacity() (int, bool)

Capacity is a method of the LimitedArrayStack type. It is used to return the maximum number of elements the stack can hold.

Returns:

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

func (*LimitedArrayStack[T]) Clear

func (stack *LimitedArrayStack[T]) Clear()

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

func (*LimitedArrayStack[T]) Copy

func (stack *LimitedArrayStack[T]) Copy() itff.Copier

Copy is a method of the LimitedArrayStack type. It is used to create a shallow copy of the stack.

Returns:

  • itf.Copier: A copy of the stack.

func (*LimitedArrayStack[T]) CutNilValues

func (stack *LimitedArrayStack[T]) CutNilValues()

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

func (*LimitedArrayStack[T]) IsEmpty

func (stack *LimitedArrayStack[T]) IsEmpty() bool

IsEmpty is a method of the LimitedArrayStack type. It is used to check if the stack is empty.

Returns:

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

func (*LimitedArrayStack[T]) IsFull

func (stack *LimitedArrayStack[T]) IsFull() (isFull bool)

IsFull is a method of the LimitedArrayStack type. It is used to check if the stack is full, i.e., if it has reached its maximum capacity.

Returns:

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

func (*LimitedArrayStack[T]) Iterator

func (stack *LimitedArrayStack[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedArrayStack type. It is used to return an iterator that iterates over the elements in the stack.

Returns:

  • itf.Iterater[T]: An iterator that iterates over the elements in the stack.

func (*LimitedArrayStack[T]) Peek

func (stack *LimitedArrayStack[T]) Peek() (T, error)

Peek is a method of the LimitedArrayStack type. It is used to return the element at the end of the stack without removing it.

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

Returns:

  • T: The element at the end of the stack.

func (*LimitedArrayStack[T]) Pop

func (stack *LimitedArrayStack[T]) Pop() (T, error)

Pop is a method of the LimitedArrayStack type. It is used to remove and return the element at the end of the stack.

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

Returns:

  • T: The element at the end of the stack.

func (*LimitedArrayStack[T]) Push

func (stack *LimitedArrayStack[T]) Push(value T) error

Push is a method of the LimitedArrayStack type. It is used to add an element to the end of the stack.

Panics with an error of type *ErrCallFailed if the stack is full.

Parameters:

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

func (*LimitedArrayStack[T]) Size

func (stack *LimitedArrayStack[T]) Size() int

Size is a method of the LimitedArrayStack type. It is used to return the number of elements in the stack.

Returns:

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

func (*LimitedArrayStack[T]) Slice

func (stack *LimitedArrayStack[T]) Slice() []T

Slice is a method of the LimitedArrayStack type. It is used to return a slice of the elements in the stack.

Returns:

  • []T: A slice of the elements in the stack.

func (*LimitedArrayStack[T]) String

func (stack *LimitedArrayStack[T]) String() string

String is a method of the LimitedArrayStack type. It is used to return a string representation of the stack, including its capacity and the elements it contains.

Returns:

  • string: A string representation of the stack.

type LimitedLinkedStack

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

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

func NewLimitedLinkedStack

func NewLimitedLinkedStack[T any](values ...T) *LimitedLinkedStack[T]

NewLimitedLinkedStack is a function that creates and returns a new instance of a LimitedLinkedStack.

Parameters:

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

Returns:

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

func (*LimitedLinkedStack[T]) Capacity

func (stack *LimitedLinkedStack[T]) Capacity() (int, bool)

Capacity is a method of the LimitedLinkedStack type. It is used to return the maximum number of elements the stack can hold.

Returns:

  • optional.Int: The maximum number of elements the stack can hold.

func (*LimitedLinkedStack[T]) Clear

func (stack *LimitedLinkedStack[T]) Clear()

Clear is a method of the LimitedLinkedStack type. It is used to remove all elements from the stack.

func (*LimitedLinkedStack[T]) Copy

func (stack *LimitedLinkedStack[T]) Copy() itff.Copier

Copy is a method of the LimitedLinkedStack type. It is used to create a shallow copy of the stack.

Returns:

  • itf.Copier: A copy of the stack.

func (*LimitedLinkedStack[T]) CutNilValues

func (stack *LimitedLinkedStack[T]) CutNilValues()

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

func (*LimitedLinkedStack[T]) IsEmpty

func (stack *LimitedLinkedStack[T]) IsEmpty() bool

IsEmpty is a method of the LimitedLinkedStack type. It is used to check if the stack is empty.

Returns:

  • bool: true if the stack is empty, and false otherwise.

func (*LimitedLinkedStack[T]) IsFull

func (stack *LimitedLinkedStack[T]) IsFull() bool

IsFull is a method of the LimitedLinkedStack type. It is used to check if the stack is full.

Returns:

  • isFull: true if the stack is full, and false otherwise.

func (*LimitedLinkedStack[T]) Iterator

func (stack *LimitedLinkedStack[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedLinkedStack type. It is used to return an iterator for the elements in the stack.

Returns:

  • itf.Iterater[T]: An iterator for the elements in the stack.

func (*LimitedLinkedStack[T]) Peek

func (stack *LimitedLinkedStack[T]) Peek() (T, error)

Peek is a method of the LimitedLinkedStack type. It is used to return the last element in the stack without removing it.

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

Returns:

  • T: The value of the last element in the stack.

func (*LimitedLinkedStack[T]) Pop

func (stack *LimitedLinkedStack[T]) Pop() (T, error)

Pop is a method of the LimitedLinkedStack type. It is used to remove and return the last element in the stack.

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

Returns:

  • T: The value of the last element in the stack.

func (*LimitedLinkedStack[T]) Push

func (stack *LimitedLinkedStack[T]) Push(value T) error

Push is a method of the LimitedLinkedStack type. It is used to add an element to the end of the stack.

Panics with an error of type *ErrCallFailed if the stack is full.

Parameters:

  • value: The value to be added to the stack.

func (*LimitedLinkedStack[T]) Size

func (stack *LimitedLinkedStack[T]) Size() int

Size is a method of the LimitedLinkedStack type. It is used to return the number of elements in the stack.

Returns:

  • int: The number of elements in the stack.

func (*LimitedLinkedStack[T]) Slice

func (stack *LimitedLinkedStack[T]) Slice() []T

Slice is a method of the LimitedLinkedStack type. It is used to return a slice of the elements in the stack.

Returns:

  • []T: A slice of the elements in the stack.

func (*LimitedLinkedStack[T]) String

func (stack *LimitedLinkedStack[T]) String() string

String is a method of the LimitedLinkedStack type. It is used to return a string representation of the stack, which includes the size, capacity, and elements in the stack.

Returns:

  • string: A string representation of the stack.

Jump to

Keyboard shortcuts

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