gmap.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with gm file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. // Package gmap provides most commonly used map container which also support concurrent-safe/unsafe switch feature.
  7. package gmap
  8. type (
  9. Map = AnyAnyMap // Map is alias of AnyAnyMap.
  10. HashMap = AnyAnyMap // HashMap is alias of AnyAnyMap.
  11. )
  12. // New creates and returns an empty hash map.
  13. // The parameter <safe> is used to specify whether using map in concurrent-safety,
  14. // which is false in default.
  15. func New(safe ...bool) *Map {
  16. return NewAnyAnyMap(safe...)
  17. }
  18. // NewFrom creates and returns a hash map from given map <data>.
  19. // Note that, the param <data> map will be set as the underlying data map(no deep copy),
  20. // there might be some concurrent-safe issues when changing the map outside.
  21. // The parameter <safe> is used to specify whether using tree in concurrent-safety,
  22. // which is false in default.
  23. func NewFrom(data map[interface{}]interface{}, safe ...bool) *Map {
  24. return NewAnyAnyMapFrom(data, safe...)
  25. }
  26. // NewHashMap creates and returns an empty hash map.
  27. // The parameter <safe> is used to specify whether using map in concurrent-safety,
  28. // which is false in default.
  29. func NewHashMap(safe ...bool) *Map {
  30. return NewAnyAnyMap(safe...)
  31. }
  32. // NewHashMapFrom creates and returns a hash map from given map <data>.
  33. // Note that, the param <data> map will be set as the underlying data map(no deep copy),
  34. // there might be some concurrent-safe issues when changing the map outside.
  35. // The parameter <safe> is used to specify whether using tree in concurrent-safety,
  36. // which is false in default.
  37. func NewHashMapFrom(data map[interface{}]interface{}, safe ...bool) *Map {
  38. return NewAnyAnyMapFrom(data, safe...)
  39. }