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() uc.Copier
- func (ds *DoubleStack[T]) CutNilValues()
- func (ds *DoubleStack[T]) GetExtracted() []T
- func (ds *DoubleStack[T]) GoString() string
- func (ds *DoubleStack[T]) IsEmpty() bool
- func (ds *DoubleStack[T]) IsFull() bool
- func (ds *DoubleStack[T]) Iterator() ui.Iterater[T]
- func (ds *DoubleStack[T]) Peek() (T, bool)
- func (ds *DoubleStack[T]) Pop() (T, bool)
- func (ds *DoubleStack[T]) Push(value T) bool
- func (ds *DoubleStack[T]) Refuse() bool
- func (ds *DoubleStack[T]) RefuseOne() bool
- func (ds *DoubleStack[T]) Size() int
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 NewDoubleStack ¶ added in v0.2.43
func NewDoubleStack[T any](stack Stacker.Stacker[T], values ...T) (*DoubleStack[T], error)
NewDoubleStack creates a new double stack that uses a specified stack as the main stack.
Parameters:
- stack: The stack to use as the main stack.
- values: The values to push onto the double stack.
Returns:
- *DoubleStack: A pointer to the new double stack.
Behaviors:
- The stack parameter is used as the main stack while values are pushed onto the end of the specified 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
Capacity returns the capacity of the double stack.
Returns:
- int: The capacity of the double stack.
func (*DoubleStack[T]) Copy ¶
func (ds *DoubleStack[T]) Copy() uc.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]) GoString ¶ added in v0.3.8
func (ds *DoubleStack[T]) GoString() string
GoString implements the fmt.GoStringer interface.
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
IsFull returns whether the double stack is full.
Returns:
- bool: Whether the double stack is full.
func (*DoubleStack[T]) Iterator ¶
func (ds *DoubleStack[T]) Iterator() ui.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, bool)
Peek returns the value at the top of the double stack without removing it.
Returns:
- T: The value at the top of the double stack.
- bool: True if the value was successfully peeked, false otherwise.
func (*DoubleStack[T]) Pop ¶
func (ds *DoubleStack[T]) Pop() (T, bool)
Pop pops a value from the double stack.
It stores the popped value in the auxiliary stack.
Returns:
- T: The value that was popped from the double stack.
- bool: True if the value was successfully popped from the double stack, false otherwise.
func (*DoubleStack[T]) Push ¶
func (ds *DoubleStack[T]) Push(value T) bool
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.
Returns:
- bool: True if the value was successfully pushed onto the double stack, false otherwise.
func (*DoubleStack[T]) Refuse ¶
func (ds *DoubleStack[T]) Refuse() bool
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.
Returns:
- bool: True if the elements were successfully refused, false otherwise.
func (*DoubleStack[T]) RefuseOne ¶
func (ds *DoubleStack[T]) RefuseOne() bool
RefuseOne refuses one element that has been popped from the stack. The element is pushed back onto the stack.
Returns:
- bool: True if the element was successfully refused, false otherwise.
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.