stack

package
v1.142.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IStack

type IStack[T any] interface {
	// Push adds elements to the stack.
	Push(value ...T)
	// PushSequence adds elements to the stack.
	PushSequence(seq iter.Seq[T])
	// Pop removes and returns an element from the stack. Returns ok true if the stack is not empty.
	Pop() (element T, ok bool)
	// Peek returns the element at the top of the stack without removing it.
	Peek() (element T, ok bool)
	// IsEmpty states whether the stack is empty. Returns ok true if the stack is not empty.
	IsEmpty() bool
	// Clear clears all elements from the stack.
	Clear()
	// Values returns all the elements in the stack. The stack will be empty as a result.
	Values() iter.Seq[T]
	// Len returns the number of elements in the stack.
	Len() int
}

IStack specifies the behaviour of a last-in, first-out (LIFO) collection. it is inspired by the work of https://github.com/hayageek/threadsafe/ and https://github.com/golang-collections/collections

func NewStack

func NewStack[T any]() IStack[T]

NewStack returns a stack which is not thread safe

func NewThreadSafeStack

func NewThreadSafeStack[T any]() IStack[T]

NewThreadSafeStack returns a thread safe stack This is inspired from https://github.com/hayageek/threadsafe

type SafeStack

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

func (*SafeStack[T]) Clear

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

func (*SafeStack[T]) IsEmpty

func (s *SafeStack[T]) IsEmpty() bool

func (*SafeStack[T]) Len

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

func (*SafeStack[T]) Peek

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

func (*SafeStack[T]) Pop

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

func (*SafeStack[T]) Push

func (s *SafeStack[T]) Push(value ...T)

func (*SafeStack[T]) PushSequence

func (s *SafeStack[T]) PushSequence(seq iter.Seq[T])

func (*SafeStack[T]) Values

func (s *SafeStack[T]) Values() iter.Seq[T]

type Stack

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

func (*Stack[T]) Clear

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

func (*Stack[T]) IsEmpty

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

func (*Stack[T]) Len

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

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (element T, ok bool)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (element T, ok bool)

Pop the top item of the stack and return it

func (*Stack[T]) Push

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

func (*Stack[T]) PushSequence

func (s *Stack[T]) PushSequence(seq iter.Seq[T])

func (*Stack[T]) Values

func (s *Stack[T]) Values() iter.Seq[T]

Jump to

Keyboard shortcuts

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