Documentation ¶
Index ¶
- type DoubleStack
- func (ds *DoubleStack[T]) Accept()
- func (ds *DoubleStack[T]) Capacity() int
- func (ds *DoubleStack[T]) Clear()
- func (ds *DoubleStack[T]) Copy() itff.Copier
- func (ds *DoubleStack[T]) CutNilValues()
- func (ds *DoubleStack[T]) GetExtracted() []T
- func (ds *DoubleStack[T]) IsEmpty() bool
- func (ds *DoubleStack[T]) IsFull() bool
- func (ds *DoubleStack[T]) Iterator() itf.Iterater[T]
- func (ds *DoubleStack[T]) Peek() (T, error)
- func (ds *DoubleStack[T]) Pop() (T, error)
- func (ds *DoubleStack[T]) Push(value T) error
- func (ds *DoubleStack[T]) Refuse() error
- func (ds *DoubleStack[T]) RefuseOne() error
- func (ds *DoubleStack[T]) Size() int
- func (ds *DoubleStack[T]) Slice() []T
- func (ds *DoubleStack[T]) String() string
- type ErrNoElementsHaveBeenPopped
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoubleStack ¶
type DoubleStack[T any] struct { // contains filtered or unexported fields }
DoubleStack is a stack that can be accepted or refused. It is used when we want to pop elements from a stack and then decide whether to accept or refuse the elements.
If the elements are accepted, they are removed from the stack. If the elements are refused, they are pushed back onto the stack as they were.
func NewDoubleArrayStack ¶
func NewDoubleArrayStack[T any](values ...T) *DoubleStack[T]
NewDoubleArrayStack creates a new double stack that uses an array stack as the main stack.
Parameters:
- values: The values to push onto the double stack.
Returns:
- *DoubleStack: A pointer to the new double stack.
func NewDoubleLinkedStack ¶
func NewDoubleLinkedStack[T any](values ...T) *DoubleStack[T]
NewDoubleLinkedStack creates a new double stack that uses a linked stack as the main stack.
Parameters:
- values: The values to push onto the double stack.
Returns:
- *DoubleStack: A pointer to the new double stack.
func (*DoubleStack[T]) Accept ¶
func (ds *DoubleStack[T]) Accept()
Accept accepts the elements that have been popped from the stack.
func (*DoubleStack[T]) Capacity ¶
func (ds *DoubleStack[T]) Capacity() int
func (*DoubleStack[T]) Copy ¶
func (ds *DoubleStack[T]) Copy() itff.Copier
Copy returns a copy of the double stack.
Returns:
- *DoubleStack: A pointer to a new double stack that is a copy of the original.
func (*DoubleStack[T]) CutNilValues ¶
func (ds *DoubleStack[T]) CutNilValues()
CutNilValues is a method that removes aCommon nil values from the double stack.
It also removes any empty or nil elements in the auxiliary stack.
func (*DoubleStack[T]) GetExtracted ¶
func (ds *DoubleStack[T]) GetExtracted() []T
GetExtracted returns the elements that have been popped from the stack.
Returns:
- []T: The elements that have been popped from the stack.
func (*DoubleStack[T]) IsEmpty ¶
func (ds *DoubleStack[T]) IsEmpty() bool
IsEmpty returns whether the double stack is empty.
Returns:
- bool: Whether the double stack is empty.
func (*DoubleStack[T]) IsFull ¶
func (ds *DoubleStack[T]) IsFull() bool
func (*DoubleStack[T]) Iterator ¶
func (ds *DoubleStack[T]) Iterator() itf.Iterater[T]
Iterator returns an iterator over the double stack.
Returns:
- Iterater[T]: A pointer to a new iterator over the double stack.
func (*DoubleStack[T]) Peek ¶
func (ds *DoubleStack[T]) Peek() (T, error)
MustPeek returns the value at the top of the double stack without removing it.
Panics with an error of type *Common.ErrEmptyList if the main stack is empty.
Returns:
- T: The value at the top of the double stack.
func (*DoubleStack[T]) Pop ¶
func (ds *DoubleStack[T]) Pop() (T, error)
MustPop pops a value from the double stack.
It stores the popped value in the auxiliary stack. Panics with an error of type *Common.ErrEmptyList if the main stack is empty.
Returns:
- T: The value that was popped from the double stack.
func (*DoubleStack[T]) Push ¶
func (ds *DoubleStack[T]) Push(value T) error
Push pushes a value onto the double stack.
(WARNING): If the auxiliary stack is not empty, values wiCommon be pushed in the middle of the stack.
Parameters:
- value (T): The value to push onto the double stack.
func (*DoubleStack[T]) Refuse ¶
func (ds *DoubleStack[T]) Refuse() error
Refuse refuses the elements that have been popped from the stack. The elements are pushed back onto the stack in the same order that they were popped.
func (*DoubleStack[T]) RefuseOne ¶
func (ds *DoubleStack[T]) RefuseOne() error
RefuseOne refuses one element that has been popped from the stack. The element is pushed back onto the stack.
Returns:
- error: An error of type *ErrNoElementsHaveBeenPopped if the auxiliary stack is empty.
func (*DoubleStack[T]) Size ¶
func (ds *DoubleStack[T]) Size() int
Size returns the number of elements in the double stack.
Returns:
- int: The number of elements in the double stack.
func (*DoubleStack[T]) Slice ¶
func (ds *DoubleStack[T]) Slice() []T
Slice returns a slice containing aCommon the elements in the double stack.
Returns:
- []T: A slice containing aCommon the elements in the double stack.
func (*DoubleStack[T]) String ¶
func (ds *DoubleStack[T]) String() string
String is a method of fmt.Stringer interface.
It should only be used for debugging and logging purposes.
Returns:
- string: A string representation of the double stack.
type ErrNoElementsHaveBeenPopped ¶
type ErrNoElementsHaveBeenPopped struct{}
ErrNoElementsHaveBeenPopped represents an error where no elements have been popped.
func NewErrNoElementsHaveBeenPopped ¶
func NewErrNoElementsHaveBeenPopped() *ErrNoElementsHaveBeenPopped
NewErrNoElementsHaveBeenPopped creates a new instance of ErrNoElementsHaveBeenPopped.
Returns:
- *ErrNoElementsHaveBeenPopped: A pointer to the newly created error.
func (*ErrNoElementsHaveBeenPopped) Error ¶
func (e *ErrNoElementsHaveBeenPopped) Error() string
Error is a method of the error interface.
Returns:
- string: The error message.