stack

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package stack provides a generic LIFO stack backed by a slice.

NOT safe for concurrent use. Callers must synchronize access externally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

Stack is a generic LIFO stack backed by a slice.

func (*Stack[T]) Clear

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

Clear removes all items from the stack.

func (*Stack[T]) Copy

func (stack *Stack[T]) Copy() *Stack[T]

Copy returns a deep copy of the stack. The new stack has independent storage but shares the same value references.

func (*Stack[T]) IsEmpty

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

IsEmpty reports whether the stack contains no elements.

func (*Stack[T]) Len

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

Len returns the number of elements in the stack.

func (*Stack[T]) Peek

func (stack *Stack[T]) Peek() T

Peek returns the top element without removing it. If the stack is empty, it returns the zero value.

func (*Stack[T]) Pop

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

Pop removes and returns the top element. If the stack is empty, it returns the zero value.

func (*Stack[T]) PopLeft

func (stack *Stack[T]) PopLeft() T

PopLeft removes and returns the bottom element. If the stack is empty, it returns the zero value.

func (*Stack[T]) Push

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

Push adds a value to the top of the stack.

func (*Stack[T]) PushLeft

func (stack *Stack[T]) PushLeft(value T)

PushLeft adds a value to the bottom of the stack.

func (*Stack[T]) Reverse

func (stack *Stack[T]) Reverse() *Stack[T]

Reverse reverses the order of elements in place and returns the stack.

func (*Stack[T]) Set

func (stack *Stack[T]) Set(values []T)

Set replaces the stack's contents with the provided slice.

func (*Stack[T]) ToSlice

func (stack *Stack[T]) ToSlice() []T

ToSlice returns a copy of the stack's elements as a slice.

Jump to

Keyboard shortcuts

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