Skip to content

Commit

Permalink
Merge pull request #5 from slashdevops/feat-golang-1.19
Browse files Browse the repository at this point in the history
Feat golang 1.19
  • Loading branch information
christiangda authored Aug 11, 2022
2 parents 9df2b0e + 094e55d commit 41b1e24
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
workflow_dispatch:

env:
GO_VERSION: 1.18
GO_VERSION: 1.19

jobs:
tests:
Expand All @@ -27,7 +27,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Show project files after make
run: tree .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
workflow_dispatch:

env:
GO_VERSION: 1.18
GO_VERSION: 1.19

permissions:
security-events: write
Expand All @@ -32,7 +32,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Show project files before make
run: tree .
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- v[0-9].[0-9]+.[0-9]*

env:
GO_VERSION: 1.18
GO_VERSION: 1.19

permissions:
id-token: write
Expand All @@ -29,7 +29,7 @@ jobs:
id: go

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Test
run: make test
Expand All @@ -46,7 +46,7 @@ jobs:
id: go

- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Show workspace files
run: tree .
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/slashdevops/r9e

go 1.18
go 1.19
1 change: 0 additions & 1 deletion godoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ Package r9e provides a collection of memory store containers.
* [MapKeyValue[K comparable, T any]](https://pkg.go.dev/github.com/slashdevops/r9e#MapKeyValue) using sync.RWMutex
* [SMapKeyValue[K comparable, T any]](https://pkg.go.dev/github.com/slashdevops/r9e#SMapKeyValue) using sync.Map
*/
package r9e
16 changes: 8 additions & 8 deletions smapkeyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
// SMapKeyValue is a generic key-value store container that is thread-safe.
// This use a golang native sync.Map data structure as underlying data structure.
type SMapKeyValue[K comparable, T any] struct {
size uint64
data sync.Map
count atomic.Uint64
data sync.Map
}

// skv is a helper struct to sort the values of the SMapKeyValue container.
Expand All @@ -23,14 +23,13 @@ type skv[K comparable, T any] struct {
// NewSMapKeyValue returns a new SMapKeyValue container.
func NewSMapKeyValue[K comparable, T any]() *SMapKeyValue[K, T] {
return &SMapKeyValue[K, T]{
size: 0,
data: sync.Map{},
}
}

// Set sets the value associated with the key.
func (r *SMapKeyValue[K, T]) Set(key K, value T) {
atomic.AddUint64(&r.size, 1)
r.count.Add(1)
r.data.Store(key, value)
}

Expand Down Expand Up @@ -67,7 +66,8 @@ func (r *SMapKeyValue[K, T]) Get(key K) T {
func (r *SMapKeyValue[K, T]) GetAnDelete(key K) (T, bool) {
value, ok := r.data.LoadAndDelete(key)
if ok {
atomic.SwapUint64(&r.size, r.size-1)
r.count.Swap(r.count.Load() - 1)

}

switch value := value.(type) {
Expand All @@ -82,19 +82,19 @@ func (r *SMapKeyValue[K, T]) GetAnDelete(key K) (T, bool) {
// Delete deletes the value associated with the key.
func (r *SMapKeyValue[K, T]) Delete(key K) {
if _, ok := r.data.LoadAndDelete(key); ok {
atomic.SwapUint64(&r.size, r.size-1)
r.count.Swap(r.count.Load() - 1)
}
}

// Clear deletes all key-value pairs stored in the container.
func (r *SMapKeyValue[K, T]) Clear() {
r.data = sync.Map{}
atomic.SwapUint64(&r.size, 0)
r.count.Swap(0)
}

// Size returns the number of key-value pairs stored in the container.
func (r *SMapKeyValue[K, T]) Size() int {
return int(r.size)
return int(r.count.Load())
}

// IsEmpty returns true if the container is empty.
Expand Down

0 comments on commit 41b1e24

Please sign in to comment.