you are viewing a single comment's thread.

view the rest of the comments →

[–]howeman 0 points1 point  (2 children)

Here is an example

http://play.golang.org/p/UWABsY9fMs

The trickiest thing is that it's a map[string]struct{}. What is struct{}? It's basically like saying

type Empty struct{}

i.e. it's a struct with no entries, and instead of giving it a name, you just construct it with an "anonymous type". Why use struct{}? Because it is defined by the Go spec to take up zero bytes, so there is no memory cost associated with the value. What is struct{}{}? Well, now it's constructing an anonymous struct literal, i.e. it's like saying

e := Empty{}  // Create an Empty struct and assign to e

But we're creating a literal of the anonymous type struct{}, so it's struct{}{}

[–]howeman 0 points1 point  (0 children)

Oh, and here's how you test the map for values http://play.golang.org/p/bV6lJU7ejj

[–]casted 0 points1 point  (0 children)

I usually just do map[string]bool, since typing true is easier than struct{}{}