Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are sets mapped to the Go type map[T]interface{}? #14

Closed
cespare opened this issue Jun 7, 2013 · 1 comment
Closed

Why are sets mapped to the Go type map[T]interface{}? #14

cespare opened this issue Jun 7, 2013 · 1 comment

Comments

@cespare
Copy link

cespare commented Jun 7, 2013

I don't understand why the thrift type set<T> is mapped to the Go type map[T]interface{}.

I think that map[T]struct{} is more appropriate -- this map uses 0 bytes for the value and is the most space-efficient representation of a set using Go maps.

An alternative that's a little more convenient is map[T]bool.

@samuel
Copy link
Owner

samuel commented Aug 21, 2013

Changed it to struct{} in latest master. The reason not bool is because the reflection encoder checks for map[T]struct{} to signify a set. It won't occur in normal use unlike map[T]bool which could and thus requires tagging the field as a set.

The encoding/decoder now support map[T]bool tagged as a set and only including keys where the value is true. This could change to be the default in the future once the code generator is creating static code for the marshall/unmarshall. For now though they rely on the reflection api.

@samuel samuel closed this as completed Aug 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants