DoubleLL

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 5 Imported by: 3

Documentation

Index

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]) Clear

func (ds *DoubleStack[T]) Clear()

Clear clears the double stack.

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]) 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() 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.

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

Error is a method of the error interface.

Returns:

  • string: The error message.

Jump to

Keyboard shortcuts

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