Skip to content

crufter/concurrent-map

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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()
	
	// Add item to map, adds "bar" under key "foo"
	map.Add("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"

license

MIT (see LICENSE file)

About

a thread-safe concurrent map for go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published