Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 17 days 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 (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-20T11:49:58.000Z (2 months ago)
- Last Synced: 2024-10-29T15:45:54.265Z (2 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
[![Go Reference](https://pkg.go.dev/badge/github.com/mdawar/syncmap.svg)](https://pkg.go.dev/github.com/mdawar/syncmap)
[![Go Report Card](https://goreportcard.com/badge/github.com/mdawar/syncmap)](https://goreportcard.com/report/github.com/mdawar/syncmap)
[![Tests](https://github.com/mdawar/syncmap/actions/workflows/test.yml/badge.svg)](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
```