Documentation ¶
Index ¶
- func NewStackWithHistory[T any](stack Stacker[T]) *ud.History[Stacker[T]]
- type ArrayStack
- func (stack *ArrayStack[T]) Capacity() int
- func (stack *ArrayStack[T]) Clear()
- func (stack *ArrayStack[T]) Copy() uc.Copier
- func (stack *ArrayStack[T]) CutNilValues()
- func (stack *ArrayStack[T]) GoString() string
- func (stack *ArrayStack[T]) IsEmpty() bool
- func (stack *ArrayStack[T]) IsFull() bool
- func (stack *ArrayStack[T]) Iterator() uc.Iterater[T]
- func (stack *ArrayStack[T]) Peek() (T, bool)
- func (stack *ArrayStack[T]) Pop() (T, bool)
- func (stack *ArrayStack[T]) Push(value T) bool
- func (stack *ArrayStack[T]) Size() int
- func (stack *ArrayStack[T]) Slice() []T
- type ClearCmd
- type CutNilValuesCmd
- type LimitedArrayStack
- func (stack *LimitedArrayStack[T]) Capacity() int
- func (stack *LimitedArrayStack[T]) Clear()
- func (stack *LimitedArrayStack[T]) Copy() uc.Copier
- func (stack *LimitedArrayStack[T]) CutNilValues()
- func (stack *LimitedArrayStack[T]) GoString() string
- func (stack *LimitedArrayStack[T]) IsEmpty() bool
- func (stack *LimitedArrayStack[T]) IsFull() (isFull bool)
- func (stack *LimitedArrayStack[T]) Iterator() uc.Iterater[T]
- func (stack *LimitedArrayStack[T]) Peek() (T, bool)
- func (stack *LimitedArrayStack[T]) Pop() (T, bool)
- func (stack *LimitedArrayStack[T]) Push(value T) bool
- func (stack *LimitedArrayStack[T]) Size() int
- func (stack *LimitedArrayStack[T]) Slice() []T
- type LimitedLinkedStack
- func (stack *LimitedLinkedStack[T]) Capacity() int
- func (stack *LimitedLinkedStack[T]) Clear()
- func (stack *LimitedLinkedStack[T]) Copy() uc.Copier
- func (stack *LimitedLinkedStack[T]) CutNilValues()
- func (stack *LimitedLinkedStack[T]) GoString() string
- func (stack *LimitedLinkedStack[T]) IsEmpty() bool
- func (stack *LimitedLinkedStack[T]) IsFull() bool
- func (stack *LimitedLinkedStack[T]) Iterator() uc.Iterater[T]
- func (stack *LimitedLinkedStack[T]) Peek() (T, bool)
- func (stack *LimitedLinkedStack[T]) Pop() (T, bool)
- func (stack *LimitedLinkedStack[T]) Push(value T) bool
- func (stack *LimitedLinkedStack[T]) Size() int
- func (stack *LimitedLinkedStack[T]) Slice() []T
- type LinkedStack
- func (stack *LinkedStack[T]) Capacity() int
- func (stack *LinkedStack[T]) Clear()
- func (stack *LinkedStack[T]) Copy() uc.Copier
- func (stack *LinkedStack[T]) CutNilValues()
- func (stack *LinkedStack[T]) GoString() string
- func (stack *LinkedStack[T]) IsEmpty() bool
- func (stack *LinkedStack[T]) IsFull() bool
- func (stack *LinkedStack[T]) Iterator() uc.Iterater[T]
- func (stack *LinkedStack[T]) Peek() (T, bool)
- func (stack *LinkedStack[T]) Pop() (T, bool)
- func (stack *LinkedStack[T]) Push(value T) bool
- func (stack *LinkedStack[T]) Size() int
- func (stack *LinkedStack[T]) Slice() []T
- type PopCmd
- type PushCmd
- type StackNode
- type Stacker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStackWithHistory ¶ added in v0.3.33
NewStackWithHistory creates a new stack that uses a specified stack as the main stack.
Parameters:
- stack: The stack to use as the main stack.
Returns:
- *ud.History[Stacker[T]]: A pointer to the new stack with history.
Behaviors:
- If the stack parameter is nil, an ArrayStack is used as the main stack.
- In executions, history errors only if it would have errored normally.
Types ¶
type ArrayStack ¶
type ArrayStack[T any] struct { // contains filtered or unexported fields }
ArrayStack is a generic type that represents a stack data structure with or without a limited capacity. It is implemented using an array.
func NewArrayStack ¶
func NewArrayStack[T any](values ...T) *ArrayStack[T]
NewArrayStack is a function that creates and returns a new instance of a ArrayStack.
Parameters:
- values: A variadic parameter of type T, which represents the initial values to be stored in the stack.
Returns:
- *ArrayStack[T]: A pointer to the newly created ArrayStack.
func (*ArrayStack[T]) Capacity ¶
func (stack *ArrayStack[T]) Capacity() int
Capacity is a method of the ArrayStack type. It is used to return the capacity of the stack.
Returns:
- int: -1
func (*ArrayStack[T]) Clear ¶
func (stack *ArrayStack[T]) Clear()
Clear is a method of the ArrayStack type. It is used to remove aCommon elements from the stack, making it empty.
func (*ArrayStack[T]) Copy ¶
func (stack *ArrayStack[T]) Copy() uc.Copier
Copy is a method of the ArrayStack type. It is used to create a shaCommonow copy of the stack.
Returns:
- uc.Copier: A copy of the stack.
func (*ArrayStack[T]) CutNilValues ¶
func (stack *ArrayStack[T]) CutNilValues()
CutNilValues is a method of the ArrayStack type. It is used to remove aCommon nil values from the stack.
func (*ArrayStack[T]) GoString ¶ added in v0.3.8
func (stack *ArrayStack[T]) GoString() string
GoString implements the fmt.GoStringer interface.
func (*ArrayStack[T]) IsEmpty ¶
func (stack *ArrayStack[T]) IsEmpty() bool
IsEmpty is a method of the ArrayStack 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 (*ArrayStack[T]) IsFull ¶
func (stack *ArrayStack[T]) IsFull() bool
IsFull is a method of the ArrayStack type. It is used to check if the stack is full.
Returns:
- bool: false
func (*ArrayStack[T]) Iterator ¶
func (stack *ArrayStack[T]) Iterator() uc.Iterater[T]
Iterator is a method of the ArrayStack type. It is used to return an iterator that iterates over the elements in the stack.
Returns:
- uc.Iterater[T]: An iterator that iterates over the elements in the stack.
func (*ArrayStack[T]) Peek ¶
func (stack *ArrayStack[T]) Peek() (T, bool)
Peek implements the Stacker interface.
func (*ArrayStack[T]) Pop ¶
func (stack *ArrayStack[T]) Pop() (T, bool)
Pop implements the Stacker interface.
func (*ArrayStack[T]) Push ¶
func (stack *ArrayStack[T]) Push(value T) bool
Push implements the Stacker interface.
Always returns true.
func (*ArrayStack[T]) Size ¶
func (stack *ArrayStack[T]) Size() int
Size is a method of the ArrayStack 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 (*ArrayStack[T]) Slice ¶
func (stack *ArrayStack[T]) Slice() []T
Slice is a method of the ArrayStack type. It is used to return a slice of the elements in the stack.
Returns:
- []T: A slice of the elements in the stack.
type ClearCmd ¶ added in v0.3.33
type ClearCmd[T any] struct { // contains filtered or unexported fields }
Clear clears the stack.
func NewClear ¶ added in v0.3.33
NewClear is a function that creates a new ClearCmd.
Returns:
- *ClearCmd: A pointer to the new ClearCmd.
type CutNilValuesCmd ¶ added in v0.3.33
type CutNilValuesCmd[T any] struct { // contains filtered or unexported fields }
CutNilValuesCmd is a command that removes nil values from the stack.
func NewCutNilValues ¶ added in v0.3.33
func NewCutNilValues[T any]() *CutNilValuesCmd[T]
CutNilValues is a method that removes aCommon nil values from the stack.
It also removes any empty or nil elements in the auxiliary stack.
func (*CutNilValuesCmd[T]) Copy ¶ added in v0.3.33
func (c *CutNilValuesCmd[T]) Copy() uc.Copier
Copy implements the Debugging.Commander interface.
func (*CutNilValuesCmd[T]) Execute ¶ added in v0.3.33
func (c *CutNilValuesCmd[T]) Execute(data Stacker[T]) error
Execute implements the Debugging.Commander interface.
Never errors.
func (*CutNilValuesCmd[T]) Undo ¶ added in v0.3.33
func (c *CutNilValuesCmd[T]) Undo(data Stacker[T]) error
Undo implements the Debugging.Commander interface.
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
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() uc.Copier
Copy is a method of the LimitedArrayStack type. It is used to create a shallow copy of the stack.
Returns:
- uc.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]) GoString ¶ added in v0.3.8
func (stack *LimitedArrayStack[T]) GoString() string
GoString implements the fmt.GoStringer interface.
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() uc.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:
- uc.Iterater[T]: An iterator that iterates over the elements in the stack.
func (*LimitedArrayStack[T]) Peek ¶
func (stack *LimitedArrayStack[T]) Peek() (T, bool)
Peek implements the Stacker interface.
func (*LimitedArrayStack[T]) Pop ¶
func (stack *LimitedArrayStack[T]) Pop() (T, bool)
Pop implements the Stacker interface.
func (*LimitedArrayStack[T]) Push ¶
func (stack *LimitedArrayStack[T]) Push(value T) bool
Push implements the Stacker interface.
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.
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
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() uc.Copier
Copy is a method of the LimitedLinkedStack type. It is used to create a shallow copy of the stack.
Returns:
- uc.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]) GoString ¶ added in v0.3.8
func (stack *LimitedLinkedStack[T]) GoString() string
GoString implements the fmt.GoStringer interface.
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() uc.Iterater[T]
Iterator is a method of the LimitedLinkedStack type. It is used to return an iterator for the elements in the stack.
Returns:
- uc.Iterater[T]: An iterator for the elements in the stack.
func (*LimitedLinkedStack[T]) Peek ¶
func (stack *LimitedLinkedStack[T]) Peek() (T, bool)
Peek implements the Stacker interface.
func (*LimitedLinkedStack[T]) Pop ¶
func (stack *LimitedLinkedStack[T]) Pop() (T, bool)
Pop implements the Stacker interface.
func (*LimitedLinkedStack[T]) Push ¶
func (stack *LimitedLinkedStack[T]) Push(value T) bool
Push implements the Stacker interface.
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.
type LinkedStack ¶
type LinkedStack[T any] struct { // contains filtered or unexported fields }
LinkedStack is a generic type that represents a stack data structure with or without a limited capacity, implemented using a linked list.
func NewLinkedStack ¶
func NewLinkedStack[T any](values ...T) *LinkedStack[T]
NewLinkedStack is a function that creates and returns a new instance of a LinkedStack.
Parameters:
- values: A variadic parameter of type T, which represents the initial values to be stored in the stack.
Returns:
- *LinkedStack[T]: A pointer to the newly created LinkedStack.
func (*LinkedStack[T]) Capacity ¶
func (stack *LinkedStack[T]) Capacity() int
Capacity is a method of the LinkedStack type. It is used to return the maximum number of elements that the stack can store.
Returns:
- int: -1
func (*LinkedStack[T]) Clear ¶
func (stack *LinkedStack[T]) Clear()
Clear is a method of the LinkedStack type. It is used to remove aCommon elements from the stack.
func (*LinkedStack[T]) Copy ¶
func (stack *LinkedStack[T]) Copy() uc.Copier
Copy is a method of the LinkedStack type. It is used to create a shaCommonow copy of the stack.
Returns:
- uc.Copier: A copy of the stack.
func (*LinkedStack[T]) CutNilValues ¶
func (stack *LinkedStack[T]) CutNilValues()
CutNilValues is a method of the LinkedStack type. It is used to remove aCommon nil values from the stack.
func (*LinkedStack[T]) GoString ¶ added in v0.3.8
func (stack *LinkedStack[T]) GoString() string
GoString implements the fmt.GoStringer interface.
func (*LinkedStack[T]) IsEmpty ¶
func (stack *LinkedStack[T]) IsEmpty() bool
IsEmpty is a method of the LinkedStack type. It is used to check if the stack is empty.
Returns:
- bool: true if the stack is empty, and false otherwise.
func (*LinkedStack[T]) IsFull ¶
func (stack *LinkedStack[T]) IsFull() bool
IsFull is a method of the LinkedStack type. It is used to check if the stack is full.
Returns:
- bool: false
func (*LinkedStack[T]) Iterator ¶
func (stack *LinkedStack[T]) Iterator() uc.Iterater[T]
Iterator is a method of the LinkedStack type. It is used to return an iterator for the elements in the stack.
Returns:
- uc.Iterater[T]: An iterator for the elements in the stack.
func (*LinkedStack[T]) Peek ¶
func (stack *LinkedStack[T]) Peek() (T, bool)
Peek implements the Stacker interface.
func (*LinkedStack[T]) Pop ¶
func (stack *LinkedStack[T]) Pop() (T, bool)
Pop implements the Stacker interface.
func (*LinkedStack[T]) Push ¶
func (stack *LinkedStack[T]) Push(value T) bool
Push implements the Stacker interface.
Always returns true.
func (*LinkedStack[T]) Size ¶
func (stack *LinkedStack[T]) Size() int
Size is a method of the LinkedStack type. It is used to return the number of elements in the stack.
Returns:
- int: The number of elements in the stack.
func (*LinkedStack[T]) Slice ¶
func (stack *LinkedStack[T]) Slice() []T
Slice is a method of the LinkedStack type. It is used to return a slice of the elements in the stack.
Returns:
- []T: A slice of the elements in the stack.
type PopCmd ¶ added in v0.3.33
type PopCmd[T any] struct { // contains filtered or unexported fields }
PopCmd is a command that pops a value from the stack.
func NewPop ¶ added in v0.3.33
NewPop is a function that creates a new PopCmd.
Returns:
- *PopCmd: A pointer to the new PopCmd.
type PushCmd ¶ added in v0.3.33
type PushCmd[T any] struct { // contains filtered or unexported fields }
PushCmd is a command that pushes a value onto the stack.
func NewPush ¶ added in v0.3.33
Push pushes a value onto the stack.
Parameters:
- value: The value to push onto the stack.
Returns:
- *PushCmd: A pointer to the new PushCmd.
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 ¶
NewStackNode is a constructor function that creates a new linkedNode with the given value.
Parameters:
- value: The value to store in the linkedNode.
Returns:
- *linkedNode: A pointer to the newly created linkedNode.
type Stacker ¶
type Stacker[T any] interface { // Push is a method that adds a value of type T to the end of the stack. // // Parameters: // - value: The value of type T to add to the stack. // // Returns: // - bool: True if the value was successfully added to the stack, false otherwise. Push(value T) bool // Pop is a method that pops an element from the stack and returns it. // // Returns: // - T: The value of type T that was popped. // - bool: True if the value was successfully popped, false otherwise. Pop() (T, bool) // Peek is a method that returns the value at the front of the stack without removing // it. // // Returns: // - T: The value of type T at the front of the stack. // - bool: True if the value was successfully peeked, false otherwise. Peek() (T, bool) ListLike.ListLike[T] }
Stacker is an interface that defines methods for a stack data structure.