2019-05-12 21:22:07 +08:00
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// 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 (
|
2019-07-29 21:01:19 +08:00
|
|
|
"github.com/gogf/gf/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.
|
2019-11-30 18:33:51 +08:00
|
|
|
// 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.
|
2019-07-23 23:20:27 +08:00
|
|
|
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),
|
|
|
|
// there might be some concurrent-safe issues when changing the map outside.
|
2019-11-30 18:33:51 +08:00
|
|
|
// 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.
|
2019-07-23 23:20:27 +08:00
|
|
|
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
|
|
|
}
|