gmap_tree_map.go 1.2 KB

123456789101112131415161718192021222324252627282930
  1. // Copyright 2017 gf Author(https://github.com/gogf/gf). 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
  7. import (
  8. "github.com/gogf/gf/container/gtree"
  9. )
  10. // Map based on red-black tree, alias of RedBlackTree.
  11. type TreeMap = gtree.RedBlackTree
  12. // NewTreeMap instantiates a tree map with the custom comparator.
  13. // The parameter <safe> is used to specify whether using tree in concurrent-safety,
  14. // which is false in default.
  15. func NewTreeMap(comparator func(v1, v2 interface{}) int, safe ...bool) *TreeMap {
  16. return gtree.NewRedBlackTree(comparator, safe...)
  17. }
  18. // NewTreeMapFrom instantiates a tree map with the custom comparator and <data> map.
  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 NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *TreeMap {
  24. return gtree.NewRedBlackTreeFrom(comparator, data, safe...)
  25. }