Code Monkey home page Code Monkey logo

concurrent-map's Introduction

concurrent map Circle CI

Golang map doesn't support concurrent reads and writes, Please see (http://golang.org/doc/faq#atomic_maps and http://blog.golang.org/go-maps-in-action), in case you're using multiple Go routines to read and write concurrently from a map some form of guard mechanism should be in-place.

Concurrent map is a wrapper around Go's map, more specifically around a String -> interface{} kinda map, which enforces concurrency.

usage

Import the package:

import (
	"github.com/streamrail/concurrent-map"
)

and go get it using the goapp gae command:

goapp get "github.com/streamrail/concurrent-map"

The package is now imported under the "cmap" namespace.

example

	// Create a new map.
	map := cmap.New()
	
	// Sets item within map, sets "bar" under key "foo"
	map.Set("foo", "bar")

	// Retrieve item from map.
	tmp, ok := map.Get("foo")

	// Checks if item exists
	if ok == true {
		// Map stores items as interface{}, hence we'll have to cast.
		bar := tmp.(string)
	}

	// Removes item under key "foo"
	map.Remove("foo")

For more examples have a look at concurrent_map_test.go.

Running tests:

go test "github.com/streamrail/concurrent-map"

templating

To generate your own custom concurrent maps please use concurrent_map_template.txt, the file is a base template for type specific maps, from terminal run:

sed 's/\<KEY\>/string/g' concurrent_map_template.go | sed 's/\<VAL\>/int/g' > cmap_string_int.go

This creates a new go source file for a string:int map.

license

MIT (see LICENSE file)

concurrent-map's People

Contributors

icholy avatar karlseguin avatar orcaman avatar swilly22 avatar

Watchers

 avatar  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.