-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
822e2b5
commit df4a81e
Showing
9 changed files
with
70 additions
and
67 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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
package maps | ||
|
||
import "sync" | ||
|
||
func NewConcurrent() *Concurrent { | ||
var cm Concurrent | ||
return &cm | ||
} | ||
|
||
type Concurrent sync.Map | ||
|
||
func (cm *Concurrent) Set(key string, value any) { | ||
(*sync.Map)(cm).Store(key, value) | ||
} | ||
|
||
func (cm *Concurrent) Get(key string) (any, bool) { | ||
return (*sync.Map)(cm).Load(key) | ||
} | ||
|
||
func (cm *Concurrent) Delete(key string) { | ||
(*sync.Map)(cm).Delete(key) | ||
} | ||
|
||
func (cm *Concurrent) Contains(key string) bool { | ||
_, ok := (*sync.Map)(cm).Load(key) | ||
return ok | ||
} | ||
|
||
func (cm *Concurrent) ToSimple() Simple { | ||
list := make(map[string]any) | ||
(*sync.Map)(cm).Range(func(key, value any) bool { | ||
list[key.(string)] = value | ||
return true | ||
}) | ||
return list | ||
} |
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,11 @@ | ||
package maps | ||
|
||
type Simple map[string]any | ||
|
||
func (m Simple) ToConcurrent() *Concurrent { | ||
var cm Concurrent | ||
for k, v := range m { | ||
cm.Set(k, v) | ||
} | ||
return &cm | ||
} |
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