gitee.com/quant1x/gox@v1.21.2/util/examples/treebidimap/treebidimap.go (about)

     1  // Copyright (c) 2015, Emir Pasic. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"gitee.com/quant1x/gox/util/internal"
     9  	"gitee.com/quant1x/gox/util/treebidimap"
    10  )
    11  
    12  // TreeBidiMapExample to demonstrate basic usage of TreeBidiMap
    13  func main() {
    14  	m := treebidimap.NewWith(internal.IntComparator, internal.StringComparator)
    15  	m.Put(1, "x")        // 1->x
    16  	m.Put(3, "b")        // 1->x, 3->b (ordered)
    17  	m.Put(1, "a")        // 1->a, 3->b (ordered)
    18  	m.Put(2, "b")        // 1->a, 2->b (ordered)
    19  	_, _ = m.GetKey("a") // 1, true
    20  	_, _ = m.Get(2)      // b, true
    21  	_, _ = m.Get(3)      // nil, false
    22  	_ = m.Values()       // []interface {}{"a", "b"} (ordered)
    23  	_ = m.Keys()         // []interface {}{1, 2} (ordered)
    24  	m.Remove(1)          // 2->b
    25  	m.Clear()            // empty
    26  	m.Empty()            // true
    27  	m.Size()             // 0
    28  }