stackedmap

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: LGPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapGetter

type MapGetter func(key any) (value any, exist bool, err error)

MapGetter defines getter method of map.

type StackedMap

type StackedMap struct {
	// contains filtered or unexported fields
}

StackedMap maintains maps in a stack. Each map inherits key/value of map that is at lower level. It acts as a map with save-restore/snapshot-revert manner.

func New

func New(src MapGetter) *StackedMap

New create an instance of StackedMap. src acts as source of data.

func (*StackedMap) Depth

func (sm *StackedMap) Depth() int

Depth returns depth of stack.

func (*StackedMap) Get

func (sm *StackedMap) Get(key any) (any, bool, error)

Get gets value for given key. The second return value indicates whether the given key is found.

func (*StackedMap) Journal

func (sm *StackedMap) Journal(cb func(key, value any) bool)

Journal traverse journal entries of all Put operations. The traverse will abort if the callback func returns false.

func (*StackedMap) Pop

func (sm *StackedMap) Pop()

Pop pop the map at top of stack. It will revert all Put operations since last Push.

func (*StackedMap) PopTo

func (sm *StackedMap) PopTo(depth int)

PopTo pop maps until stack depth reaches depth.

func (*StackedMap) Push

func (sm *StackedMap) Push() int

Push pushes a new map on stack. It returns stack depth before push.

func (*StackedMap) Put

func (sm *StackedMap) Put(key, value any)

Put puts key value into map at stack top. It will panic if stack is empty.

Jump to

Keyboard shortcuts

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