Documentation ¶
Index ¶
- type MapGetter
- type StackedMap
- func (sm *StackedMap) Depth() int
- func (sm *StackedMap) Get(key interface{}) (interface{}, bool)
- func (sm *StackedMap) Journal(cb func(key, value interface{}) bool)
- func (sm *StackedMap) Pop()
- func (sm *StackedMap) PopTo(depth int)
- func (sm *StackedMap) Push() int
- func (sm *StackedMap) Put(key, value interface{})
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) 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.