search - Set of structs containing a slice -
i'm trying implement toy search algorithm , need maintain set of explored states. state struct:
type vwstate struct { botlocation vwcoords dirtlocations []vwcoords }
my first thought simple set implemented using map[vwstate]bool
, can't seem figure out way create work. if seek utilize vwstate
key map, next panic:
panic: runtime error: hash of unhashable type vw.vwstate (pc=0x40eb0d)
is there way create work? can implement custom hashing function struct, or should looking @ other ways implement this?
any help appreciated.
you can utilize pointer struct map key:
map[*vwstate]bool
if want able compare equivalent structs, can create method output key map. string()
convenient, since utilize print struct, or tie in hash function , output shorter, int
.
something simple may suffice, though create output shorter if (being careful not recursively phone call string()
in format line):
func (s vwstate) string() string { homecoming fmt.sprintf("%#v", s) } func main() { m := make(map[string]bool) s := vwstate{} m[s.string()] = true }
search go
No comments:
Post a Comment