Skip to content

ronin13/goimutmap

Repository files navigation

Sourcegraph Go Report Card Build Status

license GoDoc

goimutmap

Introduction

This library provides:

  1. A lockless Golang map implementing the Context interface. (ContextMapper)

  2. An immutable multi-versioned map built on top of the lockless map, similarly implementing the Context interface. (ImmutMapper)

Supports: (with similar semantics as that of golang map)

a) Add

b) Exists

c) Delete

d) Iterate

ContextMapper

type IterMap struct {
	key, value interface{}
}

type ContextMapper interface {
	Exists(interface{}) (interface{}, bool)
	Add(interface{}, interface{}) interface{}
	Delete(interface{})
	Iterate() <-chan IterMap
}

As can be seen from above, it implements an interface similar to that of regular map.

ImmutMapper

type IntfMap map[interface{}]interface{}

type ImutMapper interface {
	Exists(interface{}) (interface{}, bool, IntfMap)
	Add(interface{}, interface{}) IntfMap
	Delete(interface{})
}

ImmutMapper implements similar interface, except it returns a 3rd value which is a snapshot of the map into which the operation was done.

Both ContextMapper and ImmutMapper encapsulate context.Context:

type baseMap struct {
	context.Context
	// Other internal fields
}

and provide constructors such as:

NewcontextMapper(ctx context.Context) (ContextMapper, context.CancelFunc)

and

NewImutMapper(ctx context.Context) (ImutMapper, context.CancelFunc)

and finally,

type ContextImutMapper interface {
	Exists(interface{}) (interface{}, bool, ContextMapper)
	Add(interface{}, interface{}) ContextMapper
}

which combines both ContextMapper and ImmutMapper.

Note

The key and values inserted can by of any type and heterogenous.

Please refer to godoc for more details.

Used by

Examples:

Releases

No releases published

Packages

No packages published