Skip to content

Commit 9df2b0e

Browse files
authored
Merge pull request #4 from slashdevops/fix-internal-names
fix: struct field name
2 parents 68d2764 + fca3193 commit 9df2b0e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

smapkeyvalue.go

Lines changed: 9 additions & 9 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-
count uint64
14-
data sync.Map
13+
size uint64
14+
data sync.Map
1515
}
1616

1717
// skv is a helper struct to sort the values of the SMapKeyValue container.
@@ -23,14 +23,14 @@ 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-
count: 0,
27-
data: sync.Map{},
26+
size: 0,
27+
data: sync.Map{},
2828
}
2929
}
3030

3131
// Set sets the value associated with the key.
3232
func (r *SMapKeyValue[K, T]) Set(key K, value T) {
33-
atomic.AddUint64(&r.count, 1)
33+
atomic.AddUint64(&r.size, 1)
3434
r.data.Store(key, value)
3535
}
3636

@@ -67,7 +67,7 @@ func (r *SMapKeyValue[K, T]) Get(key K) T {
6767
func (r *SMapKeyValue[K, T]) GetAnDelete(key K) (T, bool) {
6868
value, ok := r.data.LoadAndDelete(key)
6969
if ok {
70-
atomic.SwapUint64(&r.count, r.count-1)
70+
atomic.SwapUint64(&r.size, r.size-1)
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.count, r.count-1)
85+
atomic.SwapUint64(&r.size, r.size-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.count, 0)
92+
atomic.SwapUint64(&r.size, 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.count)
97+
return int(r.size)
9898
}
9999

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

0 commit comments

Comments
 (0)