2016-07-01 05:39:46 +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.
|
|
|
|
|
2018-09-19 03:40:24 +00:00
|
|
|
package main
|
2016-07-01 05:39:46 +00:00
|
|
|
|
2024-01-07 00:06:17 +00:00
|
|
|
import "github.com/emirpasic/gods/v2/maps/hashbidimap"
|
2016-07-01 05:39:46 +00:00
|
|
|
|
|
|
|
// HashBidiMapExample to demonstrate basic usage of HashMap
|
2018-09-19 03:40:24 +00:00
|
|
|
func main() {
|
2024-01-07 00:06:17 +00:00
|
|
|
m := hashbidimap.New[int, string]() // empty
|
|
|
|
m.Put(1, "x") // 1->x
|
|
|
|
m.Put(3, "b") // 1->x, 3->b (random order)
|
|
|
|
m.Put(1, "a") // 1->a, 3->b (random order)
|
|
|
|
m.Put(2, "b") // 1->a, 2->b (random order)
|
|
|
|
_, _ = m.GetKey("a") // 1, true
|
|
|
|
_, _ = m.Get(2) // b, true
|
|
|
|
_, _ = m.Get(3) // nil, false
|
|
|
|
_ = m.Values() // []interface {}{"a", "b"} (random order)
|
|
|
|
_ = m.Keys() // []interface {}{1, 2} (random order)
|
|
|
|
m.Remove(1) // 2->b
|
|
|
|
m.Clear() // empty
|
|
|
|
m.Empty() // true
|
|
|
|
m.Size() // 0
|
2016-07-01 05:39:46 +00:00
|
|
|
}
|