package genstack

import "github.com/jackc/puddle/v2/internal/genstack"

Index

Types

type GenStack

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

GenStack implements a generational stack.

GenStack works as common stack except for the fact that all elements in the older generation are guaranteed to be popped before any element in the newer generation. New elements are always pushed to the current (newest) generation.

We could also say that GenStack behaves as a stack in case of a single generation, but it behaves as a queue of individual generation stacks.

func NewGenStack

func NewGenStack[T any]() *GenStack[T]

NewGenStack creates a new empty GenStack.

func (*GenStack[T]) Len

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

Len returns number of elements in the stack.

func (*GenStack[T]) NextGen

func (s *GenStack[T]) NextGen()

NextGen starts a new stack generation.

func (*GenStack[T]) Pop

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

func (*GenStack[T]) Push

func (s *GenStack[T]) Push(v T)

Push pushes a new element at the top of the stack.

Source Files

gen_stack.go stack.go

Version
v2.2.2 (latest)
Published
Sep 10, 2024
Platform
js/wasm
Last checked
17 minutes ago

Tools for package owners.