https://github.com/msskowron/genericsafemap
Thread-safe map implementation in Golang that supports generics.
https://github.com/msskowron/genericsafemap
generics go map thread-safety
Last synced: 3 months ago
JSON representation
Thread-safe map implementation in Golang that supports generics.
- Host: GitHub
- URL: https://github.com/msskowron/genericsafemap
- Owner: MSSkowron
- License: mit
- Created: 2023-04-17T13:12:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-17T21:03:32.000Z (about 2 years ago)
- Last Synced: 2025-01-09T11:55:59.876Z (5 months ago)
- Topics: generics, go, map, thread-safety
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GenericSafeMap
GenericSafeMap is a Go library providing a thread-safe map implementation that supports generics, available from Go version 1.18 onwards. This library provides type-safe access to the underlying data structure using generics to ensure that the data stored and retrieved are of the same type.
## Installation
To use this library, you can install it using the go get command:
```
go get github.com/MSSkowron/genericsafemap
```## Usage
Here's an example of how to use the GenericSafeMap library:
```
package mainimport (
"fmt"
"github.com/MSSkowron/genericsafemap"
)func main() {
m := genericsafemap.New[string, int]()
m.Put("one", 1)
m.Put("two", 2)val, ok := m.Get("one")
if !ok {
fmt.Println("Key not found")
} else {
fmt.Println(val)
}m.Remove("one")
val, ok = m.Get("one")
if !ok {
fmt.Println("Key not found")
} else {
fmt.Println(val)
}
}
```In the above example, we create a new GenericSafeMap instance with string keys and int values, add two key-value pairs to the map, retrieve the value for key "one", remove the key "one", and then attempt to retrieve the value for "one" again.
## License
The library is available as open source under the terms of the MIT License.