github.com/wangyougui/gf/v2@v2.6.5/container/gmap/gmap_tree_map.go (about) 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/wangyougui/gf. 6 7 package gmap 8 9 import ( 10 "github.com/wangyougui/gf/v2/container/gtree" 11 ) 12 13 // TreeMap based on red-black tree, alias of RedBlackTree. 14 type TreeMap = gtree.RedBlackTree 15 16 // NewTreeMap instantiates a tree map with the custom comparator. 17 // The parameter `safe` is used to specify whether using tree in concurrent-safety, 18 // which is false in default. 19 func NewTreeMap(comparator func(v1, v2 interface{}) int, safe ...bool) *TreeMap { 20 return gtree.NewRedBlackTree(comparator, safe...) 21 } 22 23 // NewTreeMapFrom instantiates a tree map with the custom comparator and `data` map. 24 // Note that, the param `data` map will be set as the underlying data map(no deep copy), 25 // there might be some concurrent-safe issues when changing the map outside. 26 // The parameter `safe` is used to specify whether using tree in concurrent-safety, 27 // which is false in default. 28 func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *TreeMap { 29 return gtree.NewRedBlackTreeFrom(comparator, data, safe...) 30 }