FAQ
Hi all,

I'm trying to a map indexed by a bitset, or more generally, if you will, a
map indexed by an array / a slice.

The problem is that I don't necessarily want to define my array length
up-front: my index keys could be of any length, or a variable length read
from an input file.

I can't work out how to accomplish this in go, because I can't compare
slices.

Of course I can encode everything to a string, then work with those, but
it's messy. I'd much rather find a way to manage it using bitsets as the
map keys.

All the best,
Craig

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group, send email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Donovan Hide at Jan 28, 2013 at 10:30 am

    Of course I can encode everything to a string, then work with those, but
    it's messy. I'd much rather find a way to manage it using bitsets as the
    map keys.
    It is a shame that you can't define a custom hash and equality function for
    types based on slices, but I suppose immutability plays a part in that
    argument...

    Strings aren't so bad, especially if you make use of big.Int to do all the
    encoding and decoding for you:

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

    Hope that helps,
    Donovan.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group, send email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Donovan Hide at Jan 28, 2013 at 10:47 am
    If you are happy to give up readability of the underlying map you can
    achieve better storage efficiency by building strings from the byte-form of
    big.Int:

    http://play.golang.org/p/Mr2OTW-TL1

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group, send email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 28, '13 at 5:05a
activeJan 28, '13 at 10:47a
posts3
users2
websitegolang.org

2 users in discussion

Donovan Hide: 2 posts Craig Mason-Jones: 1 post

People

Translate

site design / logo © 2021 Grokbase