github.com/zhongdalu/gf@v1.0.0/g/container/gmap/gmap_tree_map.go (about)

     1  // Copyright 2017 gf Author(https://github.com/zhongdalu/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/zhongdalu/gf.
     6  
     7  package gmap
     8  
     9  import (
    10  	"github.com/zhongdalu/gf/g/container/gtree"
    11  )
    12  
    13  // Map 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 <unsafe> used to specify whether using tree in un-concurrent-safety,
    18  // which is false in default.
    19  func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe ...bool) *TreeMap {
    20  	return gtree.NewRedBlackTree(comparator, unsafe...)
    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 <unsafe> used to specify whether using tree in un-concurrent-safety,
    27  // which is false in default.
    28  func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *TreeMap {
    29  	return gtree.NewRedBlackTreeFrom(comparator, data, unsafe...)
    30  }