2016-06-27 02:21:09 +00:00
|
|
|
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2015-03-06 16:10:34 +00:00
|
|
|
|
2015-03-05 23:43:33 +00:00
|
|
|
package examples
|
|
|
|
|
|
|
|
import "github.com/emirpasic/gods/maps/treemap"
|
|
|
|
|
2016-06-24 19:52:16 +00:00
|
|
|
// TreeMapExample to demonstrate basic usage of TreeMap
|
2015-03-07 16:09:47 +00:00
|
|
|
func TreeMapExample() {
|
2015-03-05 23:43:33 +00:00
|
|
|
m := treemap.NewWithIntComparator() // empty (keys are of type int)
|
|
|
|
m.Put(1, "x") // 1->x
|
|
|
|
m.Put(2, "b") // 1->x, 2->b (in order)
|
|
|
|
m.Put(1, "a") // 1->a, 2->b (in order)
|
|
|
|
_, _ = m.Get(2) // b, true
|
|
|
|
_, _ = m.Get(3) // nil, false
|
|
|
|
_ = m.Values() // []interface {}{"a", "b"} (in order)
|
|
|
|
_ = m.Keys() // []interface {}{1, 2} (in order)
|
|
|
|
m.Remove(1) // 2->b
|
|
|
|
m.Clear() // empty
|
|
|
|
m.Empty() // true
|
|
|
|
m.Size() // 0
|
|
|
|
}
|