safestack

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: GPL-3.0 Imports: 2 Imported by: 2

README

safestack

a stack locked with a mutex to avoid race conditions

Push() and Pop() are your basic actions...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SafeStack

type SafeStack[T any] struct {
	Items []T

	Maxsize int
	// contains filtered or unexported fields
}

func NewSafeStack

func NewSafeStack[T any](items []T) *SafeStack[T]

NewSafeStack - the factory function; return a *SafeStack[T]

func (*SafeStack[T]) AssumeSafePop

func (s *SafeStack[T]) AssumeSafePop() T

AssumeSafePop - Pop() but brazenly assume that the stack is not empty

func (*SafeStack[T]) Clear

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

Clear - empty the stack

func (*SafeStack[T]) Len

func (s *SafeStack[T]) Len() int

Len - return the # of items in the stacK

func (*SafeStack[T]) NewMax

func (s *SafeStack[T]) NewMax(n int)

NewMax - set a new max stack size; trim to that size if necessary

func (*SafeStack[T]) Peek

func (s *SafeStack[T]) Peek() (T, error)

Peek - look at the top item in the stack; but do not pop it

func (*SafeStack[T]) PeekAll

func (s *SafeStack[T]) PeekAll() []T

PeekAll - return all items in the stack but leave the stack unchanged; last in first out push 1, 2, 3 -> stack [1, 2, 3] -> peek [3, 2, 1]

func (*SafeStack[T]) PeekAtSlice

func (s *SafeStack[T]) PeekAtSlice() []T

PeekAtSlice - return all items in the stack but leave the stack unchanged; first in last out push 1, 2, 3 -> stack [1, 2, 3] -> peek [1, 2, 3]

func (*SafeStack[T]) Pop

func (s *SafeStack[T]) Pop() (T, error)

Pop - pop the top item from the stack leaving it smaller by one

func (*SafeStack[T]) PopAll

func (s *SafeStack[T]) PopAll() []T

PopAll - return all items in the stack and empty the stack; last in first out push 1, 2, 3 -> stack [1, 2, 3] -> pop [3, 2, 1]

func (*SafeStack[T]) PopSlice

func (s *SafeStack[T]) PopSlice() []T

PopSlice - return all items in the stack and empty the stack; first in last out push 1, 2, 3 -> stack [1, 2, 3] -> pop [1, 2, 3]

func (*SafeStack[T]) Push

func (s *SafeStack[T]) Push(item T)

Push - add an item to the top of the stack; drop an item from the bottom if necessary

func (*SafeStack[T]) PushMany

func (s *SafeStack[T]) PushMany(items []T)

PushMany - add multiple items to the top of the stack; first in last out push [1, 2, 3] onto [0] -> stack [0, 1, 2, 3]

func (*SafeStack[T]) RePopulate

func (s *SafeStack[T]) RePopulate(items []T)

RePopulate - insert a new slice into the stack; drop down to maxsize if necessary note that here the item order is the inverse of Clear() + PushMany(): FILO vs LIFO

func (*SafeStack[T]) Reverse

func (s *SafeStack[T]) Reverse()

Reverse - invert the item order in the stack

func (*SafeStack[T]) Trim

func (s *SafeStack[T]) Trim(n int)

Trim - drop the stack size down to n

Jump to

Keyboard shortcuts

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