stackedmap

package
v1.2.0-fork7 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 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 interface{}) (value interface{}, exist bool)

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 interface{}) (interface{}, bool)

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 interface{}) 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 interface{})

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