FAQ
A Map with boolean values can be used as a Set provided that your keys have
an equality operator

     http://golang.org/doc/effective_go.html#maps

I need to create a Set of Sets so a Map won't work because it lacks an
equality operator.

Is there a way to create a Set of Sets using built ins?

--
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 golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Rui Ueyama at Aug 22, 2014 at 8:00 pm
    The first thing that came to mind is to serialize a set using gob or json
    and then use it as a key of a map. I believe there's a better way than
    this, though.

    On Fri, Aug 22, 2014 at 12:09 PM, Dean Schulze wrote:

    A Map with boolean values can be used as a Set provided that your keys
    have an equality operator

    http://golang.org/doc/effective_go.html#maps

    I need to create a Set of Sets so a Map won't work because it lacks an
    equality operator.

    Is there a way to create a Set of Sets using built ins?

    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Daniel Speed at Aug 22, 2014 at 11:03 pm
    My suggestion would be to create a hashing function for your set. Use that
    as the key to the outer map, and store the set in the value:

    I'd suggest a hashing function that's perhaps ~32 or 64 bits, and convert
    to an integer. If you're really concerned about the reliability, implement
    a full equality test and store them in a list in case of collisions.

    eg:
    type InnerSet map[string]bool

    func (i InnerSet) Hash() int64 {
    ...
    }

    func (i InnerSet) Equal(o InnerSet) bool {
         if len( )...
    }

    type SetOfSets map[int64][]InnerSet

    func (s SetOfSets) ContainsSet(o InnerSet) bool {
         hash := o.Hash()

         potentialMatches, hasHash := s[hash]

         if !hasHash {
             return false
         }

        for ... := range potentialMatches {
          .... EqualityTest
        }

        return false
    }
    On Friday, 22 August 2014 19:09:43 UTC, Dean Schulze wrote:

    A Map with boolean values can be used as a Set provided that your keys
    have an equality operator

    http://golang.org/doc/effective_go.html#maps

    I need to create a Set of Sets so a Map won't work because it lacks an
    equality operator.

    Is there a way to create a Set of Sets using built ins?
    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Egon at Aug 23, 2014 at 3:43 am

    On Friday, 22 August 2014 22:09:43 UTC+3, Dean Schulze wrote:
    A Map with boolean values can be used as a Set provided that your keys
    have an equality operator

    http://golang.org/doc/effective_go.html#maps

    I need to create a Set of Sets so a Map won't work because it lacks an
    equality operator.

    Is there a way to create a Set of Sets using built ins?
    Where do you want to use that set of sets? Depending on the context there
    can be faster or simpler solutions.

    + egon

    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Sonia Keys at Aug 24, 2014 at 8:36 pm
    Here's an example of a "simpler" solution.
      http://godoc.org/github.com/soniakeys/set It has no hashing or ordered
    data structure that would speed access, but if your sets are small it might
    be all you need.
    On Friday, August 22, 2014 11:43:47 PM UTC-4, egon wrote:


    On Friday, 22 August 2014 22:09:43 UTC+3, Dean Schulze wrote:

    A Map with boolean values can be used as a Set provided that your keys
    have an equality operator

    http://golang.org/doc/effective_go.html#maps

    I need to create a Set of Sets so a Map won't work because it lacks an
    equality operator.

    Is there a way to create a Set of Sets using built ins?
    Where do you want to use that set of sets? Depending on the context there
    can be faster or simpler solutions.

    + egon
    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Akwillis at Aug 23, 2014 at 6:25 pm
    Is this new set a union of sets or does this new set hold a group of sets?

    A simple solution would be to write a Union function that takes a group of
    sets and returns a new set. A utility library used to manage the sets could
    be as simple or as complex as you'd like, but should include the basics
    like insert, delete, contains, union, difference.

    The newest hot potato is hashing but this could be done a variety of ways,
    if the set is static then a very efficient implementation could be written
    with an array or slice using heap/btree techniques, or if its dynamic set
    the implementation could use a pointer style list, heap, b tree, avl tree,
    etc.
    On Friday, August 22, 2014 3:09:43 PM UTC-4, Dean Schulze wrote:

    A Map with boolean values can be used as a Set provided that your keys
    have an equality operator

    http://golang.org/doc/effective_go.html#maps

    I need to create a Set of Sets so a Map won't work because it lacks an
    equality operator.

    Is there a way to create a Set of Sets using built ins?
    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 22, '14 at 7:09p
activeAug 24, '14 at 8:36p
posts6
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase