https://github.com/mdawar/syncmap
A simple and generic Go map that is safe for concurrent use.
https://github.com/mdawar/syncmap
concurrent-map go map syncmap
Last synced: 3 months ago
JSON representation
A simple and generic Go map that is safe for concurrent use.
- Host: GitHub
- URL: https://github.com/mdawar/syncmap
- Owner: mdawar
- License: mit
- Created: 2024-10-20T07:26:26.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-10-20T11:49:58.000Z (9 months ago)
- Last Synced: 2025-02-09T09:29:19.311Z (5 months ago)
- Topics: concurrent-map, go, map, syncmap
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# syncmap
[](https://pkg.go.dev/github.com/mdawar/syncmap)
[](https://goreportcard.com/report/github.com/mdawar/syncmap)
[](https://github.com/mdawar/syncmap/actions/workflows/test.yml)A simple and generic **Go** map that is safe for concurrent use.
## Installation
```sh
go get -u github.com/mdawar/syncmap
```## Usage
```go
// Create a map that is safe for concurrent use.
m := syncmap.New[string, int]()// Create.
m.Set("a", 1)
m.Set("b", 2)// Get stored value.
v, ok := m.Get("a")
fmt.Println(v) // 1
fmt.Println(ok) // true// Delete.
m.Delete("b")// Map length.
m.Len()// Clear the map (Remove all entries).
m.Clear()// Iteration.
for k, v := range m.All() {
fmt.Println("Key", k, "/", "Value", v)
}
``````go
// Create a map with an initial capacity hint.
m := syncmap.NewWithCapacity[string, int](10_000)// Equivalent to.
make(map[string]int, 10_000)
```## Tests
```sh
go test -race -cover -vet=all
# If you have "just" installed.
just test
# Or using make.
make test
```