Files
gf/container/gmap/gmap_tree_map.go

31 lines
1.2 KiB
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2019-05-12 21:22:07 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with gm file,
// You can obtain one at https://github.com/gogf/gf.
package gmap
import (
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/container/gtree"
2019-05-12 21:22:07 +08:00
)
// Map based on red-black tree, alias of RedBlackTree.
type TreeMap = gtree.RedBlackTree
// NewTreeMap instantiates a tree map with the custom comparator.
// The parameter `safe` is used to specify whether using tree in concurrent-safety,
2019-05-12 21:22:07 +08:00
// which is false in default.
func NewTreeMap(comparator func(v1, v2 interface{}) int, safe ...bool) *TreeMap {
return gtree.NewRedBlackTree(comparator, safe...)
2019-05-12 21:22:07 +08:00
}
// NewTreeMapFrom instantiates a tree map with the custom comparator and `data` map.
// Note that, the param `data` map will be set as the underlying data map(no deep copy),
2019-05-12 21:22:07 +08:00
// there might be some concurrent-safe issues when changing the map outside.
// The parameter `safe` is used to specify whether using tree in concurrent-safety,
2019-05-12 21:22:07 +08:00
// which is false in default.
func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *TreeMap {
return gtree.NewRedBlackTreeFrom(comparator, data, safe...)
2019-06-19 09:06:52 +08:00
}