FAQ
(New to Golang)

Hi,

I need a data structure to store a map of string to set of attributes, for
example:

   key (string) value (map[string]float64)
========== ===================
  "p1" {'f1' 0.1, 'f2' 0.2, 'f3' 0.3}
  "p2" {'f1' 1.6, 'f2' 2.2, 'f3' 3.4}
...
..so on


What is the right way to declare and initialize this nested map data
structure?


Thanks!

--
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/groups/opt_out.

Search Discussions

  • Buntu Dev at Dec 12, 2013 at 9:02 pm

    On Thursday, December 12, 2013 1:01:15 PM UTC-8, Buntu Dev wrote:
    (New to Golang)

    Hi,

    I need a data structure to store a map of string to set of attributes, for
    example:

    key (string) value (map[string]float64)
    ========== ===================
    "p1" {'f1' 0.1, 'f2' 0.2, 'f3' 0.3}
    "p2" {'f1' 1.6, 'f2' 2.2, 'f3' 3.4}
    ...
    ..so on


    What is the right way to declare and initialize this nested map data
    structure?


    Thanks!
    --
    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/groups/opt_out.
  • Minux at Dec 12, 2013 at 10:02 pm

    On Thu, Dec 12, 2013 at 4:01 PM, Buntu Dev wrote:
    On Thursday, December 12, 2013 1:01:15 PM UTC-8, Buntu Dev wrote:

    (New to Golang)

    Hi,

    I need a data structure to store a map of string to set of attributes,
    for example:

    key (string) value (map[string]float64)
    ========== ===================
    "p1" {'f1' 0.1, 'f2' 0.2, 'f3' 0.3}
    "p2" {'f1' 1.6, 'f2' 2.2, 'f3' 3.4}
    ...
    ..so on


    What is the right way to declare and initialize this nested map data
    structure?
    var m map[string]map[string]float64
    // initialize
    m = make(map[string]map[string]float64) // you can also combine it with the
    previous line: var m = make(map[string]map[string]float64)

    // update it
    m["p1"] = map[string]float64{"f1": 0.1, "f2": 0.2}

    see: http://play.golang.org/p/BLnN2AVl1o

    --
    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/groups/opt_out.
  • Rodrigo Kochenburger at Dec 12, 2013 at 9:04 pm
    http://play.golang.org/p/wC5hZW_-MJ

    - RK

    On Thu, Dec 12, 2013 at 1:01 PM, Buntu Dev wrote:

    (New to Golang)

    Hi,

    I need a data structure to store a map of string to set of attributes, for
    example:

    key (string) value (map[string]float64)
    ========== ===================
    "p1" {'f1' 0.1, 'f2' 0.2, 'f3' 0.3}
    "p2" {'f1' 1.6, 'f2' 2.2, 'f3' 3.4}
    ...
    ..so on


    What is the right way to declare and initialize this nested map data
    structure?


    Thanks!

    --
    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/groups/opt_out.
    --
    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/groups/opt_out.
  • Buntu Dev at Dec 12, 2013 at 9:06 pm
    Thanks!
    On Thursday, December 12, 2013 1:04:02 PM UTC-8, Rodrigo Kochenburger wrote:

    http://play.golang.org/p/wC5hZW_-MJ

    - RK


    On Thu, Dec 12, 2013 at 1:01 PM, Buntu Dev <bunt...@gmail.com<javascript:>
    wrote:
    (New to Golang)

    Hi,

    I need a data structure to store a map of string to set of attributes,
    for example:

    key (string) value (map[string]float64)
    ========== ===================
    "p1" {'f1' 0.1, 'f2' 0.2, 'f3' 0.3}
    "p2" {'f1' 1.6, 'f2' 2.2, 'f3' 3.4}
    ...
    ..so on


    What is the right way to declare and initialize this nested map data
    structure?


    Thanks!

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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/groups/opt_out.
  • Keith Randall at Dec 12, 2013 at 11:49 pm
    A more efficient way would be to use a single map with a pair of strings as
    the key:

    http://play.golang.org/p/4fTTUO6L-a

    The only downside is that you lose the ability to efficiently count and/or
    iterate over all attributes for a single key.

    On Thursday, December 12, 2013 1:01:15 PM UTC-8, Buntu Dev wrote:

    (New to Golang)

    Hi,

    I need a data structure to store a map of string to set of attributes, for
    example:

    key (string) value (map[string]float64)
    ========== ===================
    "p1" {'f1' 0.1, 'f2' 0.2, 'f3' 0.3}
    "p2" {'f1' 1.6, 'f2' 2.2, 'f3' 3.4}
    ...
    ..so on


    What is the right way to declare and initialize this nested map data
    structure?


    Thanks!
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 12, '13 at 9:01p
activeDec 12, '13 at 11:49p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase