GithubHelp home page GithubHelp logo

ronin13 / goimutmap Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 27 KB

An immutable lockless Golang map

License: MIT License

Go 98.75% Makefile 1.25%
golang-map golang-library lockless map immutable

goimutmap's Introduction

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:

goimutmap's People

Contributors

ronin13 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.