I'm trying to create a map in Go that is keyed by big integers. Effective Go explicitly says that:
Structs, arrays and slices cannot be used as map keys, because equality is not defined on those types.
which makes sense. I could of course convert the big integers to strings and use the string as a key, but I'm looking for a more general solution here. Can I wrap my structure into something (an interface?) that implements an equality function and use that instead?
Example code that, of course, doesn't work:
package main
import (
"big"
"fmt"
)
func main() {
one1 := big.NewInt(1)
one2 := big.NewInt(1)
hmap := make(map[*big.Int] int)
hmap[one1] = 2
_, exists := hmap[one2]
fmt.Printf("Exists=%v\n", exists)
}