### Install HaxMap Source: https://github.com/alphadose/haxmap/blob/main/README.md Install the HaxMap library using the go get command. Requires Go 1.18.x or above. ```bash go get github.com/alphadose/haxmap ``` -------------------------------- ### Basic HaxMap Usage Source: https://github.com/alphadose/haxmap/blob/main/README.md Demonstrates initializing, setting, getting, iterating, and deleting key-value pairs in a HaxMap. Safe to delete non-existent keys. ```go package main import ( "fmt" "github.com/alphadose/haxmap" ) func main() { // initialize map with key type `int` and value type `string` mep := haxmap.New[int, string]() // set a value (overwrites existing value if present) mep.Set(1, "one") // get the value and print it val, ok := mep.Get(1) if ok { println(val) } mep.Set(2, "two") mep.Set(3, "three") mep.Set(4, "four") // ForEach loop to iterate over all key-value pairs and execute the given lambda mep.ForEach(func(key int, value string) bool { fmt.Printf("Key -> %d | Value -> %s\n", key, value) return true // return `true` to continue iteration and `false` to break iteration }) mep.Del(1) // delete a value mep.Del(0) // delete is safe even if a key doesn't exists // bulk deletion is supported too in the same API call // has better performance than deleting keys one by one mep.Del(2, 3, 4) if mep.Len() == 0 { println("cleanup complete") } } ``` -------------------------------- ### Custom String Hash Function Source: https://github.com/alphadose/haxmap/blob/main/README.md Example of overriding the default xxHash algorithm with a custom hash function for string keys. The custom hash function must adhere to the `func(keyType) uintptr` signature. ```go package main import ( "github.com/alphadose/haxmap" ) // your custom hash function // the hash function signature must adhere to `func(keyType) uintptr` func customStringHasher(s string) uintptr { return uintptr(len(s)) } func main() { m := haxmap.New[string, string]() // initialize a string-string map m.SetHasher(customStringHasher) // this overrides the default xxHash algorithm m.Set("one", "1") val, ok := m.Get("one") if ok { println(val) } } ``` -------------------------------- ### Pre-allocate HaxMap Size Source: https://github.com/alphadose/haxmap/blob/main/README.md Demonstrates pre-allocating the initial size of a HaxMap to potentially improve performance by preventing grow operations until the specified limit is reached. ```go package main import ( "github.com/alphadose/haxmap" ) func main() { const initialSize = 1 << 10 // pre-allocating the size of the map will prevent all grow operations // until that limit is hit thereby improving performance m := haxmap.New[int, string](initialSize) m.Set(1, "1") val, ok := m.Get(1) if ok { println(val) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.