FAQ
I am a newbie to go. I found this library [github.com/deckarep/golang-set/]
mentioned in the documentation somewhere. I was curious why it is
implemented the way it is.

https://github.com/deckarep/golang-set/blob/master/threadunsafe.go :
type threadUnsafeSet map[interface{}]struct{}

I was wondering why it is not just threadUnsafeSet map[interface{}]bool

Am I missing something here?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Jun 15, 2015 at 9:57 pm

    On Mon, Jun 15, 2015 at 12:17 PM, Tanmay Binaykiya wrote:

    I am a newbie to go. I found this library [github.com/deckarep/golang-set/]
    mentioned in the documentation somewhere. I was curious why it is
    implemented the way it is.

    https://github.com/deckarep/golang-set/blob/master/threadunsafe.go :
    type threadUnsafeSet map[interface{}]struct{}

    I was wondering why it is not just threadUnsafeSet map[interface{}]bool

    Am I missing something here?
    It probably could be map[interface{}]bool.

    The advantage of using struct{} is that using bool takes an extra byte
    per entry in the map. If you store hundreds of millions of entries,
    that can add up.

    For almost all uses, bool is fine, and it's a bit easier to write code
    using bool.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
  • Matt Harden at Jun 15, 2015 at 10:39 pm
    Another downside of using bool is that it's possible to store false, and
    then would that key be in the set or not? struct{} means the *only*
    information in the map is whether each key is present or not.
    On Mon, Jun 15, 2015 at 4:57 PM Ian Lance Taylor wrote:

    On Mon, Jun 15, 2015 at 12:17 PM, Tanmay Binaykiya
    wrote:
    I am a newbie to go. I found this library [
    github.com/deckarep/golang-set/]
    mentioned in the documentation somewhere. I was curious why it is
    implemented the way it is.

    https://github.com/deckarep/golang-set/blob/master/threadunsafe.go :
    type threadUnsafeSet map[interface{}]struct{}

    I was wondering why it is not just threadUnsafeSet map[interface{}]bool

    Am I missing something here?
    It probably could be map[interface{}]bool.

    The advantage of using struct{} is that using bool takes an extra byte
    per entry in the map. If you store hundreds of millions of entries,
    that can add up.

    For almost all uses, bool is fine, and it's a bit easier to write code
    using bool.

    Ian

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 15, '15 at 9:55p
activeJun 15, '15 at 10:39p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase