2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2018-01-03 10:38:53 +08:00
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
2019-02-01 17:30:23 +08:00
|
|
|
// If a copy of the MIT was not distributed with gm file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-01-03 10:38:53 +08:00
|
|
|
|
2020-05-22 12:04:58 +08:00
|
|
|
// Package gmap provides most commonly used map container which also support concurrent-safe/unsafe switch feature.
|
2018-01-03 10:38:53 +08:00
|
|
|
package gmap
|
2019-05-08 17:21:18 +08:00
|
|
|
|
2020-04-07 20:06:26 +08:00
|
|
|
type (
|
|
|
|
|
Map = AnyAnyMap // Map is alias of AnyAnyMap.
|
|
|
|
|
HashMap = AnyAnyMap // HashMap is alias of AnyAnyMap.
|
|
|
|
|
)
|
2019-05-11 20:47:25 +08:00
|
|
|
|
2019-11-30 18:33:51 +08:00
|
|
|
// New creates and returns an empty hash map.
|
2021-09-16 20:57:59 +08:00
|
|
|
// The parameter `safe` is used to specify whether using map in concurrent-safety,
|
2019-07-23 23:20:27 +08:00
|
|
|
// which is false in default.
|
|
|
|
|
func New(safe ...bool) *Map {
|
|
|
|
|
return NewAnyAnyMap(safe...)
|
2019-05-08 17:21:18 +08:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 20:57:59 +08:00
|
|
|
// NewFrom creates and returns a hash map from given map `data`.
|
|
|
|
|
// Note that, the param `data` map will be set as the underlying data map(no deep copy),
|
2019-05-08 17:21:18 +08:00
|
|
|
// there might be some concurrent-safe issues when changing the map outside.
|
2021-09-16 20:57:59 +08:00
|
|
|
// The parameter `safe` is used to specify whether using tree in concurrent-safety,
|
2019-05-11 20:47:25 +08:00
|
|
|
// which is false in default.
|
2019-07-23 23:20:27 +08:00
|
|
|
func NewFrom(data map[interface{}]interface{}, safe ...bool) *Map {
|
|
|
|
|
return NewAnyAnyMapFrom(data, safe...)
|
2019-05-09 22:53:42 +08:00
|
|
|
}
|
|
|
|
|
|
2019-11-30 18:33:51 +08:00
|
|
|
// NewHashMap creates and returns an empty hash map.
|
2021-09-16 20:57:59 +08:00
|
|
|
// The parameter `safe` is used to specify whether using map in concurrent-safety,
|
2019-07-23 23:20:27 +08:00
|
|
|
// which is false in default.
|
|
|
|
|
func NewHashMap(safe ...bool) *Map {
|
|
|
|
|
return NewAnyAnyMap(safe...)
|
2019-05-08 17:21:18 +08:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 20:57:59 +08:00
|
|
|
// NewHashMapFrom creates and returns a hash map from given map `data`.
|
|
|
|
|
// Note that, the param `data` map will be set as the underlying data map(no deep copy),
|
2019-05-11 20:47:25 +08:00
|
|
|
// there might be some concurrent-safe issues when changing the map outside.
|
2021-09-16 20:57:59 +08:00
|
|
|
// The parameter `safe` is used to specify whether using tree in concurrent-safety,
|
2019-05-11 20:47:25 +08:00
|
|
|
// which is false in default.
|
2019-07-23 23:20:27 +08:00
|
|
|
func NewHashMapFrom(data map[interface{}]interface{}, safe ...bool) *Map {
|
|
|
|
|
return NewAnyAnyMapFrom(data, safe...)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|