@@ -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.
1212type 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.
2424func 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.
3232func (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 {
6767func (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.
8383func (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.
9090func (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.
9696func (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