a thread-safe concurrent map for go
Go
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 21 commits behind orcaman:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
concurrent_map.go
concurrent_map_bench_test.go
concurrent_map_test.go

README.md

concurrent map Circle CI

As explained here and here, the map type in Go doesn't support concurrent reads and writes. concurrent-map provides a high-performance solution to this by sharding the map with minimal time spent waiting for locks.

usage

Import the package:

import (
	"github.com/streamrail/concurrent-map"
)
go 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.
	if tmp, ok := map.Get("foo"); ok {
		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)