stacker

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 2 Imported by: 0

README

Stacker

A Go (and TinyGo) stack implementation shared by a few of my projects.

Based on

Something I saw at https://stackoverflow.com/questions/28541609/looking-for-reasonable-stack-implementation-in-golang

Testing

There are tests, just use go test ./... to run them.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stacker

type Stacker[Type any] struct {
	Data []Type
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------

func NewStacker

func NewStacker[Type any]() *Stacker[Type]

----------------------------------------------------------------------------

func (*Stacker[Type]) Length

func (stacker *Stacker[Type]) Length() int

---------------------------------------------------------------------------- Returns the number of elements in the stack

func (*Stacker[Type]) Peek

func (stacker *Stacker[Type]) Peek() (Type, error)

---------------------------------------------------------------------------- Returns the first entry in the stack, does not remove it, can error on empty

func (*Stacker[Type]) Pop

func (stacker *Stacker[Type]) Pop() (Type, error)

---------------------------------------------------------------------------- Pops and returns the first item on the stack, possibly error if the stack is empty

func (*Stacker[Type]) Push

func (stacker *Stacker[Type]) Push(element Type)

---------------------------------------------------------------------------- Pushed a new item into the stack

Jump to

Keyboard shortcuts

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