{"id":13564338,"url":"https://github.com/orcaman/concurrent-map","last_synced_at":"2025-05-14T22:06:23.829Z","repository":{"id":21499706,"uuid":"24818657","full_name":"orcaman/concurrent-map","owner":"orcaman","description":"a thread-safe concurrent map for go","archived":false,"fork":false,"pushed_at":"2024-05-22T08:17:29.000Z","size":101,"stargazers_count":4433,"open_issues_count":38,"forks_count":553,"subscribers_count":69,"default_branch":"master","last_synced_at":"2025-05-07T21:16:48.251Z","etag":null,"topics":["concurrency","concurrent-programming","go","golang","map","thread-safety"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orcaman.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-05T15:22:51.000Z","updated_at":"2025-05-07T20:55:44.000Z","dependencies_parsed_at":"2023-01-13T21:31:30.559Z","dependency_job_id":"8b804145-a741-492a-a87a-a9a558bdbf0f","html_url":"https://github.com/orcaman/concurrent-map","commit_stats":{"total_commits":95,"total_committers":36,"mean_commits":2.638888888888889,"dds":0.7684210526315789,"last_synced_commit":"85296bce05256a80153a9e0c2bf6f4e167a4fe8d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orcaman%2Fconcurrent-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orcaman%2Fconcurrent-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orcaman%2Fconcurrent-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orcaman%2Fconcurrent-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orcaman","download_url":"https://codeload.github.com/orcaman/concurrent-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235694,"owners_count":22036963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","concurrent-programming","go","golang","map","thread-safety"],"created_at":"2024-08-01T13:01:29.949Z","updated_at":"2025-05-14T22:06:23.794Z","avatar_url":"https://github.com/orcaman.png","language":"Go","readme":"# concurrent map [![Build Status](https://travis-ci.com/orcaman/concurrent-map.svg?branch=master)](https://travis-ci.com/orcaman/concurrent-map)\n\n正如 [这里](http://golang.org/doc/faq#atomic_maps) 和 [这里](http://blog.golang.org/go-maps-in-action)所描述的, Go语言原生的`map`类型并不支持并发读写。`concurrent-map`提供了一种高性能的解决方案:通过对内部`map`进行分片，降低锁粒度，从而达到最少的锁等待时间(锁冲突)\n\n在Go 1.9之前，go语言标准库中并没有实现并发`map`。在Go 1.9中，引入了`sync.Map`。新的`sync.Map`与此`concurrent-map`有几个关键区别。标准库中的`sync.Map`是专为`append-only`场景设计的。因此，如果您想将`Map`用于一个类似内存数据库，那么使用我们的版本可能会受益。你可以在golang repo上读到更多，[这里](https://github.com/golang/go/issues/21035) and [这里](https://stackoverflow.com/questions/11063473/map-with-concurrent-access)\n***译注:`sync.Map`在读多写少性能比较好，否则并发性能很差***\n\n## 用法\n\n导入包:\n\n```go\nimport (\n\t\"github.com/orcaman/concurrent-map/v2\"\n)\n\n```\n\n```bash\ngo get \"github.com/orcaman/concurrent-map/v2\"\n```\n\n现在包被导入到了`cmap`命名空间下\n***译注:通常包的限定前缀(命名空间)是和目录名一致的，但是这个包有点典型😂，不一致！！！所以用的时候注意***\n\n## 示例\n\n```go\n\n\t// 创建一个新的 map.\n\tm := cmap.New[string]()\n\n\t// 设置变量m一个键为“foo”值为“bar”键值对\n\tm.Set(\"foo\", \"bar\")\n\n\t// 从m中获取指定键值.\n\tbar, ok := m.Get(\"foo\")\n\n\t// 删除键为“foo”的项\n\tm.Remove(\"foo\")\n\n```\n\n更多使用示例请查看`concurrent_map_test.go`.\n\n运行测试:\n\n```bash\ngo test \"github.com/orcaman/concurrent-map/v2\"\n```\n\n## 贡献说明\n\n我们非常欢迎大家的贡献。如欲合并贡献，请遵循以下指引:\n- 新建一个issue,并且叙述为什么这么做(解决一个bug，增加一个功能，等等)\n- 根据核心团队对上述问题的反馈，提交一个PR，描述变更并链接到该问题。\n- 新代码必须具有测试覆盖率。\n- 如果代码是关于性能问题的，则必须在流程中包括基准测试(无论是在问题中还是在PR中)。\n- 一般来说，我们希望`concurrent-map`尽可能简单，且与原生的`map`有相似的操作。当你新建issue时请注意这一点。\n\n## 许可证\nMIT (see [LICENSE](https://github.com/orcaman/concurrent-map/blob/master/LICENSE) file)\n","funding_links":[],"categories":["Misc","开源类库","Go","Data structures","Open source library","Repositories","开发工具\u0026框架"],"sub_categories":["开发辅助包","Development Aid Package"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forcaman%2Fconcurrent-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forcaman%2Fconcurrent-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forcaman%2Fconcurrent-map/lists"}