stack

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[T any] func(option *Options[T])

Option is a function type used to set Options

func WithContainer

func WithContainer[T any](c container.Container[T]) Option[T]

WithContainer is used to set a stack's underlying container

func WithGoroutineSafe

func WithGoroutineSafe[T any]() Option[T]

WithGoroutineSafe is used to set a stack goroutine-safe

func WithListContainer

func WithListContainer[T any]() Option[T]

WithListContainer is used to set List for a stack's underlying container

type Options

type Options[T any] struct {
	// contains filtered or unexported fields
}

Options holds the Stack's options

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack is a last-in-first-out data structure

func New

func New[T any](opts ...Option[T]) *Stack[T]

New creates a new stack

func (*Stack[T]) Clear

func (s *Stack[T]) Clear()

Clear clears all elements in the stack

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

Empty returns true if the stack is empty, otherwise returns false

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop removes the top value in the stack and returns it

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

Push pushes a value to the stack

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

Size returns the amount of elements in the stack

func (*Stack[T]) String

func (s *Stack[T]) String() string

String returns a string representation of the stack

func (*Stack[T]) Top

func (s *Stack[T]) Top() T

Top returns the top value in the stack

Jump to

Keyboard shortcuts

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