# HashMap HashMap is a key value map data structure.
## Source - [https://github.com/duke-git/lancet/blob/main/datastructure/hashmap/hashmap.go](https://github.com/duke-git/lancet/blob/main/datastructure/hashmap/hashmap.go)
## Usage ```go import ( hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) ```
## Index - [NewHashMap](#NewHashMap) - [NewHashMapWithCapacity](#NewHashMapWithCapacity) - [Get](#Get) - [Put](#Put) - [Delete](#Delete) - [Contains](#Contains) - [Iterate](#Iterate) - [Keys](#Keys) - [Values](#Values)
## Documentation ### NewHashMap

Make a HashMap instance with default capacity is 1 << 10.

Signature: ```go func NewHashMap() *HashMap ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() fmt.Println(hm) } ``` ### NewHashMap

Make a HashMap instance with given size and capacity.

Signature: ```go func NewHashMapWithCapacity(size, capacity uint64) *HashMap ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMapWithCapacity(uint64(100), uint64(1000)) fmt.Println(hm) } ``` ### Get

Get the value of given key in hashmap

Signature: ```go func (hm *HashMap) Get(key any) any ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() val := hm.Get("a") fmt.Println(val) //nil } ``` ### Put

Put new key value in hashmap, then return value

Signature: ```go func (hm *HashMap) Put(key any, value any) any ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() hm.Put("a", 1) val := hm.Get("a") fmt.Println(val) //1 } ``` ### Delete

Delete key-value item by given key in hashmap.

Signature: ```go func (hm *HashMap) Delete(key any) ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() hm.Put("a", 1) val := hm.Get("a") fmt.Println(val) //1 hm.Delete("a") val = hm.Get("a") fmt.Println(val) //nil } ``` ### Contains

Checks if given key is in hashmap or not.

Signature: ```go func (hm *HashMap) Contains(key any) bool ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() hm.Put("a", 1) fmt.Println(hm.Contains("a")) //true fmt.Println(hm.Contains("b")) //false } ``` ### Iterate

Executes iteratee funcation for every key and value pair of hashmap.

Signature: ```go func (hm *HashMap) Iterate(iteratee func(key, value any)) ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() hm.Put("a", 1) hm.Put("b", 2) hm.Put("c", 3) hm.Iterate(func(key, value any) { fmt.Println(key) fmt.Println(value) }) } ``` ### Keys

Return a slice of the hashmap's keys (random order).

Signature: ```go func (hm *HashMap) Keys() []any ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() hm.Put("a", 1) hm.Put("b", 2) hm.Put("c", 3) keys := hm.Keys() fmt.Println(keys) //[]interface{"a", "b", "c"} } ``` ### Values

Return a slice of the hashmap's values (random order).

Signature: ```go func (hm *HashMap) Values() []any ``` Example: ```go package main import ( "fmt" hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" ) func main() { hm := heap.NewHashMap() hm.Put("a", 1) hm.Put("b", 2) hm.Put("c", 3) values := hm.Values() fmt.Println(values) //[]interface{2, 1, 3} } ```