Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aidenwallis/safemap
Very simple Golang hashmap implementation with RW mutexes for concurrent access.
https://github.com/aidenwallis/safemap
Last synced: about 5 hours ago
JSON representation
Very simple Golang hashmap implementation with RW mutexes for concurrent access.
- Host: GitHub
- URL: https://github.com/aidenwallis/safemap
- Owner: aidenwallis
- License: gpl-3.0
- Created: 2019-07-08T17:14:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-08T18:09:35.000Z (over 5 years ago)
- Last Synced: 2024-06-20T08:03:36.007Z (8 months ago)
- Language: Go
- Homepage:
- Size: 73.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# safemap
[![GoDoc](https://godoc.org/github.com/aidenwallis/safemap?status.svg)](https://godoc.org/github.com/aidenwallis/safemap)
[![Build Status](https://travis-ci.org/aidenwallis/safemap.svg?branch=master)](https://travis-ci.org/aidenwallis/safemap)
[![Coverage Status](https://coveralls.io/repos/github/aidenwallis/safemap/badge.svg?branch=master)](https://coveralls.io/github/aidenwallis/safemap?branch=master)A dead simple hashmap implementation that allows you to not worry about concurrent access/writes through the use of RWMutexes.
## Why use a lock?
This package is intended to just be a very simple and easy-to-use utility, rather than being a complex solution that doesn't use locks etc. The aim is to keep this package as bearbones as possible and just provide a simple interface for using the hashmap.
While many other solutions can be more performant, locks for many use cases are completely fine for creating a thread-safe implementation of a hashmap without experiencing any serious performance issues at fairly decent scale.
## Using the implementation
This package is incredibly easy to use, like so
```go
package mainimport (
"fmt""github.com/aidenwallis/safemap"
)func main() {
hashmap := safemap.New()hashmap.Set("key", "value")
value, ok := hashmap.Get("key")
if ok {
// This key exists in the hashmap.
fmt.Println("Key value: " + value.(string))
}// Delete a key from the hashmap.
hashmap.Delete("key")exists := hashmap.Has("Key")
if !exists {
fmt.Println("Key no longer exists in hashmap")
}
count := hashmap.Count()
fmt.Println("Only ", count, " values are in the hashmap!")
}
```