-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made lib generic * Switched to 1.18 build * Removed deps step * Switched off modules * Added mod init * Adding GOPATH * Try path again * Used newer action * Set unstable * Fixed version number * Try numbering again * More version format nonsense * Added paths * Added go.mod * Refactoring * Generified README * Clarified and commented * Shifted to typed sync maps Co-authored-by: Sudhir Jonathan <[email protected]>
- Loading branch information
Showing
6 changed files
with
105 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/sudhirj/cirque | ||
|
||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cirque | ||
|
||
import "sync" | ||
|
||
type SyncMap[K comparable, V any] struct { | ||
holder map[K]V | ||
lock sync.RWMutex | ||
} | ||
|
||
func NewSyncMap[K comparable, V any]() *SyncMap[K, V] { | ||
return &SyncMap[K, V]{ | ||
holder: make(map[K]V), | ||
lock: sync.RWMutex{}, | ||
} | ||
} | ||
|
||
func (tm *SyncMap[K, V]) Set(key K, value V) { | ||
tm.lock.Lock() | ||
tm.holder[key] = value | ||
tm.lock.Unlock() | ||
} | ||
|
||
func (tm *SyncMap[K, V]) Get(key K) (value V, ok bool) { | ||
tm.lock.RLock() | ||
defer tm.lock.RUnlock() | ||
value, ok = tm.holder[key] | ||
return | ||
} | ||
|
||
func (tm *SyncMap[K, V]) Delete(key K) { | ||
tm.lock.Lock() | ||
delete(tm.holder, key) | ||
tm.lock.Unlock() | ||
} |