arraystack

package
v0.0.0-...-27558a4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[E any] func(*Stack[E]) error

Option is funtional option type for configuring a Stack.

func WithSafe

func WithSafe[E any]() Option[E]

WithSafe creates a option that make the array-backed stack safe for concurrent use.

type Stack

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

Stack represents a stack backed by a slice. The stack provides typical LIFO(last-in, first-out) behavior.

func New

func New[E any](ops ...Option[E]) (*Stack[E], error)

New creates and initializes a empty stack. Options can be provided to customize the stack's properties (e.g., thread safety).

func NewFromMapKeys

func NewFromMapKeys[K comparable, V any](m map[K]V, ops ...Option[K]) (*Stack[K], error)

NewFromMapKeys creates and initializes a stack from the provided map keys. Options can be provided to customize the stack's properties (e.g., thread safety). Returns an empty stack if the provided map is nil or empty.

func NewFromMapValues

func NewFromMapValues[K comparable, V any](m map[K]V, ops ...Option[V]) (*Stack[V], error)

NewFromMapValues creates a stack from the provided map values. Options can be provided to customize the stack's properties (e.g., thread safety). Returns an empty stack if the provided map is nil or empty.

func NewFromSlice

func NewFromSlice[E any](slice []E, ops ...Option[E]) (*Stack[E], error)

NewFromSlice creates and initializes a stack from the provided slice, the last element of the slice on top. Options can be provided to customize the stack's properties (e.g., thread safety).

func (*Stack[E]) Clear

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

Clear removes all elements from the stack.

func (*Stack[E]) Clone

func (s *Stack[E]) Clone() *Stack[E]

Clone returns a deep copy of the stack.

func (*Stack[E]) IsEmpty

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

IsEmpty reports whether the stack has no elements.

func (*Stack[E]) Len

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

Len returns the number of elements currently in the stack.

func (*Stack[E]) MarshalJSON

func (s *Stack[E]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the stack into a JSON array, the top of the stack first, the order Values lists it in.

func (*Stack[E]) Peek

func (s *Stack[E]) Peek() (E, bool)

Peek returns the top element of the stack without removing it. Returns the zero value of E and false if the stack is empty.

func (*Stack[E]) Pop

func (s *Stack[E]) Pop() (E, bool)

Pop removes and returns the top element of the stack. Returns the zero value of E and false if the stack is empty.

func (*Stack[E]) Push

func (s *Stack[E]) Push(e E)

Push adds an element to the top of the stack. The stack's size increases by one.

func (*Stack[E]) String

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

String returns a string representation of the stack.

func (*Stack[E]) UnmarshalJSON

func (s *Stack[E]) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON replaces the stack with the elements of a JSON array read in the order MarshalJSON writes: the first element ends up on top.

func (*Stack[E]) Values

func (s *Stack[E]) Values() []E

Values returns all elements in the stack in LIFO(last-in, first-out) order. If the stack is empty, it returns an empty slice (not nil).

Jump to

Keyboard shortcuts

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