mirror of
https://github.com/emirpasic/gods.git
synced 2026-06-14 16:06:42 +03:00
14f714261f
* Generics migration This attempts to migrate this library in the least invasive way by preserving as much of the original API as possible. It does not change the tests in a meaningful way nor does it attempt to upgrade any logic that can be simplified or improved with generics. This is purely an API migration, and still requires a lot of additional work to be fully ready. * Fix a few broken tests around serialization * Add v2 suffix * Temporarily change mod name for testing * Rename module to /v2
24 lines
908 B
Go
24 lines
908 B
Go
// 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.
|
|
|
|
package main
|
|
|
|
import "github.com/emirpasic/gods/v2/maps/hashmap"
|
|
|
|
// HashMapExample to demonstrate basic usage of HashMap
|
|
func main() {
|
|
m := hashmap.New[int, string]() // empty
|
|
m.Put(1, "x") // 1->x
|
|
m.Put(2, "b") // 2->b, 1->x (random order)
|
|
m.Put(1, "a") // 2->b, 1->a (random order)
|
|
_, _ = m.Get(2) // b, true
|
|
_, _ = m.Get(3) // nil, false
|
|
_ = m.Values() // []interface {}{"b", "a"} (random order)
|
|
_ = m.Keys() // []interface {}{1, 2} (random order)
|
|
m.Remove(1) // 2->b
|
|
m.Clear() // empty
|
|
m.Empty() // true
|
|
m.Size() // 0
|
|
}
|