Documentation
¶
Overview ¶
Package ListLike provides a Stacker interface that defines methods for a stack data structure.
Index ¶
- type ArrayStack
- func (stack *ArrayStack[T]) Clear()
- func (stack *ArrayStack[T]) Copy() itf.Copier
- func (stack *ArrayStack[T]) CutNilValues()
- func (stack *ArrayStack[T]) IsEmpty() bool
- func (stack *ArrayStack[T]) Iterator() itf.Iterater[T]
- func (stack *ArrayStack[T]) MustPeek() T
- func (stack *ArrayStack[T]) MustPop() T
- func (stack *ArrayStack[T]) Peek() (T, error)
- func (stack *ArrayStack[T]) Pop() (T, error)
- func (stack *ArrayStack[T]) Push(value T)
- func (stack *ArrayStack[T]) Size() int
- func (stack *ArrayStack[T]) Slice() []T
- func (stack *ArrayStack[T]) String() string
- type LinkedStack
- func (stack *LinkedStack[T]) Clear()
- func (stack *LinkedStack[T]) Copy() itf.Copier
- func (stack *LinkedStack[T]) CutNilValues()
- func (stack *LinkedStack[T]) IsEmpty() bool
- func (stack *LinkedStack[T]) Iterator() itf.Iterater[T]
- func (stack *LinkedStack[T]) MustPeek() T
- func (stack *LinkedStack[T]) MustPop() T
- func (stack *LinkedStack[T]) Peek() (T, error)
- func (stack *LinkedStack[T]) Pop() (T, error)
- func (stack *LinkedStack[T]) Push(value T)
- func (stack *LinkedStack[T]) Size() int
- func (stack *LinkedStack[T]) Slice() []T
- func (stack *LinkedStack[T]) String() string
- type Stacker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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]) Clear ¶
func (stack *ArrayStack[T]) Clear()
Clear is a method of the ArrayStack type. It is used to remove all elements from the stack, making it empty.
func (*ArrayStack[T]) Copy ¶
func (stack *ArrayStack[T]) Copy() itf.Copier
Copy is a method of the ArrayStack type. It is used to create a shallow copy of the stack.
Returns:
- itf.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 all nil values from the stack.
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]) Iterator ¶
func (stack *ArrayStack[T]) Iterator() itf.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:
- itf.Iterater[T]: An iterator that iterates over the elements in the stack.
func (*ArrayStack[T]) MustPeek ¶ added in v0.2.21
func (stack *ArrayStack[T]) MustPeek() T
Peek is a method of the ArrayStack type. It is used to return the element at the end of the stack without removing it.
Panics with an error of type *ll.ErrEmptyList if the stack is empty.
Returns:
- T: The element at the end of the stack.
func (*ArrayStack[T]) MustPop ¶ added in v0.2.21
func (stack *ArrayStack[T]) MustPop() T
Pop is a method of the ArrayStack type. It is used to remove and return the element at the end of the stack.
Panics with an error of type *ll.ErrEmptyList if the stack is empty.
Returns:
- T: The element at the end of the stack.
func (*ArrayStack[T]) Peek ¶
func (stack *ArrayStack[T]) Peek() (T, error)
Peek is a method of the ArrayStack 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 (*ArrayStack[T]) Pop ¶
func (stack *ArrayStack[T]) Pop() (T, error)
Pop is a method of the ArrayStack 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 (*ArrayStack[T]) Push ¶
func (stack *ArrayStack[T]) Push(value T)
Push is a method of the ArrayStack 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 (*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.
func (*ArrayStack[T]) String ¶
func (stack *ArrayStack[T]) String() string
String is a method of the ArrayStack 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 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]) Clear ¶
func (stack *LinkedStack[T]) Clear()
Clear is a method of the LinkedStack type. It is used to remove all elements from the stack.
func (*LinkedStack[T]) Copy ¶
func (stack *LinkedStack[T]) Copy() itf.Copier
Copy is a method of the LinkedStack type. It is used to create a shallow copy of the stack.
Returns:
- itf.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 all nil values from the stack.
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]) Iterator ¶
func (stack *LinkedStack[T]) Iterator() itf.Iterater[T]
Iterator is a method of the LinkedStack 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 (*LinkedStack[T]) MustPeek ¶ added in v0.2.21
func (stack *LinkedStack[T]) MustPeek() T
Peek is a method of the LinkedStack type. It is used to return the last element in the stack without removing it.
Panics with an error of type *ll.ErrEmptyList if the stack is empty.
Returns:
- T: The value of the last element in the stack.
func (*LinkedStack[T]) MustPop ¶ added in v0.2.21
func (stack *LinkedStack[T]) MustPop() T
MustPop is a method of the LinkedStack type. It is used to remove and return the last element in the stack.
Panics with an error of type *ll.ErrEmptyList if the stack is empty.
Returns:
- T: The value of the last element in the stack.
func (*LinkedStack[T]) Peek ¶
func (stack *LinkedStack[T]) Peek() (T, error)
Peek is a method of the LinkedStack 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 (*LinkedStack[T]) Pop ¶
func (stack *LinkedStack[T]) Pop() (T, error)
Pop is a method of the LinkedStack 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 (*LinkedStack[T]) Push ¶
func (stack *LinkedStack[T]) Push(value T)
Push is a method of the LinkedStack 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 (*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.
func (*LinkedStack[T]) String ¶
func (stack *LinkedStack[T]) String() string
String is a method of the LinkedStack 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.
type Stacker ¶
type Stacker[T any] interface { // The Push method adds a value of type T to the end of the stack. // If the stack is full, it will panic. Push(value T) // The Pop method pops an element from the stack and returns it. // If the stack is empty, it will return an error. Pop() (T, error) // The MustPop method pops an element from the stack and returns it. // If the stack is empty, it will panic. MustPop() 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 error. Peek() (T, error) // 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. MustPeek() T // .ListLike[T] is an interface that defines methods for a stack data structure. ListLike.ListLike[T] }
Stacker is an interface that defines methods for a stack data structure.