concurrent-map

a thread-safe concurrent map for go

Github星跟蹤圖

concurrent map Build Status

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.

Prior to Go 1.9, there was no concurrent map implementation in the stdlib. In Go 1.9, sync.Map was introduced. The new sync.Map has a few key differences from this map. The stdlib sync.Map is designed for append-only scenarios. So if you want to use the map for something more like in-memory db, you might benefit from using our version. You can read more about it in the golang repo, for example here and here

usage

Import the package:

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

go get "github.com/orcaman/concurrent-map"

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

example


	// Create a new map.
	m := cmap.New()

	// Sets item within map, sets "bar" under key "foo"
	m.Set("foo", "bar")

	// Retrieve item from map.
	if tmp, ok := m.Get("foo"); ok {
		bar := tmp.(string)
	}

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

For more examples have a look at concurrent_map_test.go.

Running tests:

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

guidelines for contributing

Contributions are highly welcome. In order for a contribution to be merged, please follow these guidelines:

  • Open an issue and describe what you are after (fixing a bug, adding an enhancement, etc.).
  • According to the core team's feedback on the above mentioned issue, submit a pull request, describing the changes and linking to the issue.
  • New code must have test coverage.
  • If the code is about performance issues, you must include benchmarks in the process (either in the issue or in the PR).
  • In general, we would like to keep concurrent-map as simple as possible and as similar to the native map. Please keep this in mind when opening issues.

language

license

MIT (see LICENSE file)

主要指標

概覽
名稱與所有者orcaman/concurrent-map
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2014-10-05 15:22:51
推送於2024-05-22 08:17:29
最后一次提交2022-11-08 14:17:03
發布數4
最新版本名稱v2.0.1 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數4.4k
關注者數69
派生數553
提交數141
已啟用問題?
問題數72
打開的問題數24
拉請求數43
打開的拉請求數14
關閉的拉請求數27
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?