mapInterface.go 459 B

123456789101112131415161718192021222324252627
  1. package dataStruct
  2. import "sync"
  3. type DMapInterface struct {
  4. RWLock sync.Mutex
  5. Map *sync.Map
  6. }
  7. func NewDMapInterface() *DMapInterface {
  8. m := &DMapInterface{
  9. Map: new(sync.Map),
  10. }
  11. return m
  12. }
  13. func (m *DMapInterface) Add(key interface{}, val interface{}) {
  14. m.Map.Store(key, val)
  15. }
  16. func (m *DMapInterface) Remove(key interface{}) {
  17. m.Map.Delete(key)
  18. }
  19. func (m *DMapInterface) Get(key interface{}) (interface{}, bool) {
  20. return m.Map.Load(key)
  21. }