Skip to content

Commit 41b1e24

Browse files
authored
Merge pull request #5 from slashdevops/feat-golang-1.19
Feat golang 1.19
2 parents 9df2b0e + 094e55d commit 41b1e24

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

.github/workflows/gosec.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
workflow_dispatch:
1313

1414
env:
15-
GO_VERSION: 1.18
15+
GO_VERSION: 1.19
1616

1717
jobs:
1818
tests:
@@ -27,7 +27,7 @@ jobs:
2727
go-version: ${{ env.GO_VERSION }}
2828

2929
- name: Check out code
30-
uses: actions/checkout@v2
30+
uses: actions/checkout@v3
3131

3232
- name: Show project files after make
3333
run: tree .

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
workflow_dispatch:
1313

1414
env:
15-
GO_VERSION: 1.18
15+
GO_VERSION: 1.19
1616

1717
permissions:
1818
security-events: write
@@ -32,7 +32,7 @@ jobs:
3232
go-version: ${{ env.GO_VERSION }}
3333

3434
- name: Check out code
35-
uses: actions/checkout@v2
35+
uses: actions/checkout@v3
3636

3737
- name: Show project files before make
3838
run: tree .

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- v[0-9].[0-9]+.[0-9]*
99

1010
env:
11-
GO_VERSION: 1.18
11+
GO_VERSION: 1.19
1212

1313
permissions:
1414
id-token: write
@@ -29,7 +29,7 @@ jobs:
2929
id: go
3030

3131
- name: Check out code
32-
uses: actions/checkout@v2
32+
uses: actions/checkout@v3
3333

3434
- name: Test
3535
run: make test
@@ -46,7 +46,7 @@ jobs:
4646
id: go
4747

4848
- name: Check out code
49-
uses: actions/checkout@v2
49+
uses: actions/checkout@v3
5050

5151
- name: Show workspace files
5252
run: tree .

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/slashdevops/r9e
22

3-
go 1.18
3+
go 1.19

godoc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ Package r9e provides a collection of memory store containers.
55
66
* [MapKeyValue[K comparable, T any]](https://pkg.go.dev/github.com/slashdevops/r9e#MapKeyValue) using sync.RWMutex
77
* [SMapKeyValue[K comparable, T any]](https://pkg.go.dev/github.com/slashdevops/r9e#SMapKeyValue) using sync.Map
8-
98
*/
109
package r9e

smapkeyvalue.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
// SMapKeyValue is a generic key-value store container that is thread-safe.
1111
// This use a golang native sync.Map data structure as underlying data structure.
1212
type SMapKeyValue[K comparable, T any] struct {
13-
size uint64
14-
data sync.Map
13+
count atomic.Uint64
14+
data sync.Map
1515
}
1616

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

3130
// Set sets the value associated with the key.
3231
func (r *SMapKeyValue[K, T]) Set(key K, value T) {
33-
atomic.AddUint64(&r.size, 1)
32+
r.count.Add(1)
3433
r.data.Store(key, value)
3534
}
3635

@@ -67,7 +66,8 @@ func (r *SMapKeyValue[K, T]) Get(key K) T {
6766
func (r *SMapKeyValue[K, T]) GetAnDelete(key K) (T, bool) {
6867
value, ok := r.data.LoadAndDelete(key)
6968
if ok {
70-
atomic.SwapUint64(&r.size, r.size-1)
69+
r.count.Swap(r.count.Load() - 1)
70+
7171
}
7272

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

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

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

100100
// IsEmpty returns true if the container is empty.

0 commit comments

Comments
 (0)