{"id":13411519,"url":"https://github.com/lrita/cmap","last_synced_at":"2025-04-28T20:31:57.185Z","repository":{"id":47441577,"uuid":"224098087","full_name":"lrita/cmap","owner":"lrita","description":"a thread-safe concurrent map for go","archived":false,"fork":false,"pushed_at":"2023-11-08T12:22:30.000Z","size":24,"stargazers_count":91,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-31T20:46:10.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/lrita.png","metadata":{"files":{"readme":"README.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":"2019-11-26T03:54:59.000Z","updated_at":"2024-06-14T10:23:54.000Z","dependencies_parsed_at":"2024-06-18T16:57:32.943Z","dependency_job_id":"df90ccbe-7c0d-4acb-bde3-05559615a90e","html_url":"https://github.com/lrita/cmap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fcmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fcmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fcmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lrita%2Fcmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lrita","download_url":"https://codeload.github.com/lrita/cmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251383830,"owners_count":21580945,"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":[],"created_at":"2024-07-30T20:01:14.208Z","updated_at":"2025-04-28T20:31:56.882Z","avatar_url":"https://github.com/lrita.png","language":"Go","readme":"# cmap [![Build Status](https://travis-ci.org/lrita/cmap.svg?branch=master)](https://travis-ci.org/lrita/cmap) [![GoDoc](https://godoc.org/github.com/lrita/cmap?status.png)](https://godoc.org/github.com/lrita/cmap) [![codecov](https://codecov.io/gh/lrita/cmap/branch/master/graph/badge.svg)](https://codecov.io/gh/lrita/cmap) [![Go Report Card](https://goreportcard.com/badge/github.com/lrita/cmap)](https://goreportcard.com/report/github.com/lrita/cmap)\n\nThe `map` type in Go doesn't support concurrent reads and writes. `cmap(concurrent-map)` provides a high-performance solution to this by sharding the map with minimal time spent waiting for locks.\n\nThe `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](https://github.com/golang/go/issues/21035) and [here](https://stackoverflow.com/questions/11063473/map-with-concurrent-access)\n\n_Here we fork some README document from [concurrent-map](https://github.com/orcaman/concurrent-map)_\n\n## usage\n\nImport the package:\n\n```go\nimport (\n\t\"github.com/lrita/cmap\"\n)\n\n```\n\n```bash\ngo get \"github.com/lrita/cmap\"\n```\n\nThe package is now imported under the \"cmap\" namespace.\n\n## example\n\n```go\n\n\t// Create a new map.\n\tvar m cmap.Cmap\n\n\t// Stores item within map, sets \"bar\" under key \"foo\"\n\tm.Store(\"foo\", \"bar\")\n\n\t// Retrieve item from map.\n\tif tmp, ok := m.Load(\"foo\"); ok {\n\t\tbar := tmp.(string)\n\t}\n\n\t// Deletes item under key \"foo\"\n\tm.Delete(\"foo\")\n\n\t// If you are using g1.18+, you can use the generics implementation\n\n\tvar n cmap.Map[string, string]\n\n\t// Stores item within map, sets \"bar\" under key \"foo\"\n\tn.Store(\"foo\", \"bar\")\n\n\t// Retrieve item from map.\n\tif tmp, ok := n.Load(\"foo\"); ok {\n\t    bar := tmp\n\t}\n\n\t// Deletes item under key \"foo\"\n\tn.Delete(\"foo\")\n```\n\n## benchmark\n\n```bash\ngoos: darwin\ngoarch: amd64\npkg: github.com/lrita/cmap\nBenchmarkLoadMostlyHits/*cmap_test.DeepCopyMap-4         \t50000000\t        34.5 ns/op\nBenchmarkLoadMostlyHits/*cmap_test.RWMutexMap-4          \t20000000\t        65.2 ns/op\nBenchmarkLoadMostlyHits/*sync.Map-4                      \t50000000\t        34.8 ns/op\nBenchmarkLoadMostlyHits/*cmap.Cmap-4                     \t30000000\t        53.5 ns/op\nBenchmarkLoadMostlyMisses/*cmap_test.DeepCopyMap-4       \t50000000\t        26.7 ns/op\nBenchmarkLoadMostlyMisses/*cmap_test.RWMutexMap-4        \t20000000\t        62.5 ns/op\nBenchmarkLoadMostlyMisses/*sync.Map-4                    \t50000000\t        22.7 ns/op\nBenchmarkLoadMostlyMisses/*cmap.Cmap-4                   \t30000000\t        40.3 ns/op\n--- SKIP: BenchmarkLoadOrStoreBalanced/*cmap_test.DeepCopyMap\n    cmap_bench_test.go:91: DeepCopyMap has quadratic running time.\nBenchmarkLoadOrStoreBalanced/*cmap_test.RWMutexMap-4     \t 3000000\t       437 ns/op\nBenchmarkLoadOrStoreBalanced/*sync.Map-4                 \t 3000000\t       546 ns/op\nBenchmarkLoadOrStoreBalanced/*cmap.Cmap-4                \t 3000000\t       497 ns/op\n--- SKIP: BenchmarkLoadOrStoreUnique/*cmap_test.DeepCopyMap\n    cmap_bench_test.go:123: DeepCopyMap has quadratic running time.\nBenchmarkLoadOrStoreUnique/*cmap_test.RWMutexMap-4       \t 2000000\t       990 ns/op\nBenchmarkLoadOrStoreUnique/*sync.Map-4                   \t 1000000\t      1032 ns/op\nBenchmarkLoadOrStoreUnique/*cmap.Cmap-4                  \t 2000000\t       892 ns/op\nBenchmarkLoadOrStoreCollision/*cmap_test.DeepCopyMap-4   \t100000000\t        18.2 ns/op\nBenchmarkLoadOrStoreCollision/*cmap_test.RWMutexMap-4    \t10000000\t       165 ns/op\nBenchmarkLoadOrStoreCollision/*sync.Map-4                \t100000000\t        19.6 ns/op\nBenchmarkLoadOrStoreCollision/*cmap.Cmap-4               \t20000000\t        65.7 ns/op\nBenchmarkRange/*cmap_test.DeepCopyMap-4                  \t  200000\t      8646 ns/op\nBenchmarkRange/*cmap_test.RWMutexMap-4                   \t   20000\t     62046 ns/op\nBenchmarkRange/*sync.Map-4                               \t  200000\t      9317 ns/op\nBenchmarkRange/*cmap.Cmap-4                              \t   50000\t     31107 ns/op\nBenchmarkAdversarialAlloc/*cmap_test.DeepCopyMap-4       \t 2000000\t       531 ns/op\nBenchmarkAdversarialAlloc/*cmap_test.RWMutexMap-4        \t20000000\t        74.3 ns/op\nBenchmarkAdversarialAlloc/*sync.Map-4                    \t 5000000\t       390 ns/op\nBenchmarkAdversarialAlloc/*cmap.Cmap-4                   \t30000000\t        53.6 ns/op\nBenchmarkAdversarialDelete/*cmap_test.DeepCopyMap-4      \t 5000000\t       273 ns/op\nBenchmarkAdversarialDelete/*cmap_test.RWMutexMap-4       \t20000000\t        94.4 ns/op\nBenchmarkAdversarialDelete/*sync.Map-4                   \t10000000\t       137 ns/op\nBenchmarkAdversarialDelete/*cmap.Cmap-4                  \t30000000\t        43.3 ns/op\n```\n","funding_links":[],"categories":["数据结构与算法","Uncategorized","Data Structures and Algorithms","Data Structures","数据结构","数据结构`go语言实现的数据结构与算法`","Data Integration Frameworks","Generators"],"sub_categories":["地图","Maps","Advanced Console UIs","Standard CLI","标准 CLI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flrita%2Fcmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flrita%2Fcmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flrita%2Fcmap/lists"}