Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #3516 > unrolled thread
| Started by | Victor Porton <porton@narod.ru> |
|---|---|
| First post | 2013-06-22 21:19 +0300 |
| Last post | 2013-06-24 20:36 +0300 |
| Articles | 9 — 2 participants |
Back to article view | Back to comp.programming
Generating multi-level associative arrays Victor Porton <porton@narod.ru> - 2013-06-22 21:19 +0300
Re: Generating multi-level associative arrays Rui Maciel <rui.maciel@gmail.com> - 2013-06-23 08:30 +0100
Re: Generating multi-level associative arrays Victor Porton <porton@narod.ru> - 2013-06-23 15:16 +0300
Re: Generating multi-level associative arrays Rui Maciel <rui.maciel@gmail.com> - 2013-06-23 16:02 +0100
Re: Generating multi-level associative arrays Victor Porton <porton@narod.ru> - 2013-06-23 18:06 +0300
Re: Generating multi-level associative arrays Rui Maciel <rui.maciel@gmail.com> - 2013-06-23 18:52 +0100
Re: Generating multi-level associative arrays Victor Porton <porton@narod.ru> - 2013-06-24 14:52 +0300
Re: Generating multi-level associative arrays Victor Porton <porton@narod.ru> - 2013-06-24 14:53 +0300
Solved: Generating multi-level associative arrays Victor Porton <porton@narod.ru> - 2013-06-24 20:36 +0300
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2013-06-22 21:19 +0300 |
| Subject | Generating multi-level associative arrays |
| Message-ID | <kq4ps2$ds$1@speranza.aioe.org> |
Suppose we have an array each element of which is an associative array: [[a:1, b:2, c:3], ...] I want to create an associative array out of it, indexed by values of some key (such as the key "a"): [1:[[a:1, b:2, c:3], ...], ...] (a value "1" of the key may be met more than once, thus with the value "1" of the key "a" is associated an array [[a:1, b:2, c:3], ...] not just [a:1, b:2, c:3]. It is easy to program in any modern language. But what is the best way to do this if we want a MULTILEVEL associative array? (indexed by first key "a", then by key "b", etc.) I want to discuss the most elegant, short, and practical solution for this kind of problems. We could even write practically usable libraries of real code to do this kind of things. Note that in fact I use PHP. -- Victor Porton - http://portonvictor.org
[toc] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2013-06-23 08:30 +0100 |
| Message-ID | <kq67tn$1k3$1@dont-email.me> |
| In reply to | #3516 |
Victor Porton wrote: > But what is the best way to do this if we want a MULTILEVEL associative > array? (indexed by first key "a", then by key "b", etc.) > > I want to discuss the most elegant, short, and practical solution for this > kind of problems. I don't know if it's the most elegant, but if you wish to have multiple keys map to a value then you can resort to a tuple containing both keys as your map's key. That approach is very common. For example, with the "dictionary of keys" matrix data structure, the matrix elements are stored in a key:value pair whose key is a (row, column) tuple. Hope this helps, Rui Maciel
[toc] | [prev] | [next] | [standalone]
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2013-06-23 15:16 +0300 |
| Message-ID | <kq6ouc$mpp$1@speranza.aioe.org> |
| In reply to | #3528 |
Rui Maciel wrote: > Victor Porton wrote: > >> But what is the best way to do this if we want a MULTILEVEL associative >> array? (indexed by first key "a", then by key "b", etc.) >> >> I want to discuss the most elegant, short, and practical solution for >> this kind of problems. > > I don't know if it's the most elegant, but if you wish to have multiple > keys map to a value then you can resort to a tuple containing both keys as > your map's key. > > That approach is very common. For example, with the "dictionary of keys" > matrix data structure, the matrix elements are stored in a key:value pair > whose key is a (row, column) tuple. It seems you have misunderstood me. I ask about forming a *multilevel* associative array like: [1:[2:[[a:1, b:2, c:3],...]]] where "1" a value of the key "a", "2" is a value of the key "b", etc. -- Victor Porton - http://portonvictor.org
[toc] | [prev] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2013-06-23 16:02 +0100 |
| Message-ID | <kq72c0$v1k$1@dont-email.me> |
| In reply to | #3529 |
Victor Porton wrote: > Rui Maciel wrote: > >> Victor Porton wrote: >> >>> But what is the best way to do this if we want a MULTILEVEL associative >>> array? (indexed by first key "a", then by key "b", etc.) >>> >>> I want to discuss the most elegant, short, and practical solution for >>> this kind of problems. >> >> I don't know if it's the most elegant, but if you wish to have multiple >> keys map to a value then you can resort to a tuple containing both keys >> as your map's key. >> >> That approach is very common. For example, with the "dictionary of keys" >> matrix data structure, the matrix elements are stored in a key:value pair >> whose key is a (row, column) tuple. > > It seems you have misunderstood me. I ask about forming a *multilevel* > associative array like: > > [1:[2:[[a:1, b:2, c:3],...]]] > > where "1" a value of the key "a", "2" is a value of the key "b", etc. > What do you mean by "multi-level"? For example, from your example, by multi- level do you mean that in order to access the value in the a:1 key value pair, the map goes something like: example_map[1][2][a] == 1 ? Rui Maciel
[toc] | [prev] | [next] | [standalone]
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2013-06-23 18:06 +0300 |
| Message-ID | <kq72u1$jc4$1@speranza.aioe.org> |
| In reply to | #3535 |
Rui Maciel wrote: > Victor Porton wrote: > >> Rui Maciel wrote: >> >>> Victor Porton wrote: >>> >>>> But what is the best way to do this if we want a MULTILEVEL associative >>>> array? (indexed by first key "a", then by key "b", etc.) >>>> >>>> I want to discuss the most elegant, short, and practical solution for >>>> this kind of problems. >>> >>> I don't know if it's the most elegant, but if you wish to have multiple >>> keys map to a value then you can resort to a tuple containing both keys >>> as your map's key. >>> >>> That approach is very common. For example, with the "dictionary of >>> keys" matrix data structure, the matrix elements are stored in a >>> key:value pair whose key is a (row, column) tuple. >> >> It seems you have misunderstood me. I ask about forming a *multilevel* >> associative array like: >> >> [1:[2:[[a:1, b:2, c:3],...]]] >> >> where "1" a value of the key "a", "2" is a value of the key "b", etc. >> > > What do you mean by "multi-level"? For example, from your example, by > multi- level do you mean that in order to access the value in the a:1 key > value pair, the map goes something like: > > example_map[1][2][a] == 1 ? Yes, well almost: example_map[1][2] (without [a]) -- Victor Porton - http://portonvictor.org
[toc] | [prev] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2013-06-23 18:52 +0100 |
| Message-ID | <kq7cau$obd$1@dont-email.me> |
| In reply to | #3536 |
Victor Porton wrote: > Rui Maciel wrote: > >> Victor Porton wrote: >> >>> Rui Maciel wrote: >>> >>>> Victor Porton wrote: >>>> >>>>> But what is the best way to do this if we want a MULTILEVEL >>>>> associative array? (indexed by first key "a", then by key "b", etc.) >>>>> >>>>> I want to discuss the most elegant, short, and practical solution for >>>>> this kind of problems. >>>> >>>> I don't know if it's the most elegant, but if you wish to have multiple >>>> keys map to a value then you can resort to a tuple containing both keys >>>> as your map's key. >>>> >>>> That approach is very common. For example, with the "dictionary of >>>> keys" matrix data structure, the matrix elements are stored in a >>>> key:value pair whose key is a (row, column) tuple. >>> >>> It seems you have misunderstood me. I ask about forming a *multilevel* >>> associative array like: >>> >>> [1:[2:[[a:1, b:2, c:3],...]]] >>> >>> where "1" a value of the key "a", "2" is a value of the key "b", etc. >>> >> >> What do you mean by "multi-level"? For example, from your example, by >> multi- level do you mean that in order to access the value in the a:1 key >> value pair, the map goes something like: >> >> example_map[1][2][a] == 1 ? > > Yes, well almost: > > example_map[1][2] (without [a]) Just to get things straight, you expect an outcome similar to the following pseudo-ish code? example_map[1][2] == 1 Rui Maciel
[toc] | [prev] | [next] | [standalone]
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2013-06-24 14:52 +0300 |
| Message-ID | <kq9btq$i1g$2@speranza.aioe.org> |
| In reply to | #3542 |
Rui Maciel wrote: > Victor Porton wrote: > >> Rui Maciel wrote: >> >>> Victor Porton wrote: >>> >>>> Rui Maciel wrote: >>>> >>>>> Victor Porton wrote: >>>>> >>>>>> But what is the best way to do this if we want a MULTILEVEL >>>>>> associative array? (indexed by first key "a", then by key "b", etc.) >>>>>> >>>>>> I want to discuss the most elegant, short, and practical solution for >>>>>> this kind of problems. >>>>> >>>>> I don't know if it's the most elegant, but if you wish to have >>>>> multiple keys map to a value then you can resort to a tuple containing >>>>> both keys as your map's key. >>>>> >>>>> That approach is very common. For example, with the "dictionary of >>>>> keys" matrix data structure, the matrix elements are stored in a >>>>> key:value pair whose key is a (row, column) tuple. >>>> >>>> It seems you have misunderstood me. I ask about forming a *multilevel* >>>> associative array like: >>>> >>>> [1:[2:[[a:1, b:2, c:3],...]]] >>>> >>>> where "1" a value of the key "a", "2" is a value of the key "b", etc. >>>> >>> >>> What do you mean by "multi-level"? For example, from your example, by >>> multi- level do you mean that in order to access the value in the a:1 >>> key value pair, the map goes something like: >>> >>> example_map[1][2][a] == 1 ? >> >> Yes, well almost: >> >> example_map[1][2] (without [a]) > > Just to get things straight, you expect an outcome similar to the > following pseudo-ish code? > > example_map[1][2] == 1 example_map[1][2] == [a:1, b:2, c:3] > Rui Maciel -- Victor Porton - http://portonvictor.org
[toc] | [prev] | [next] | [standalone]
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2013-06-24 14:53 +0300 |
| Message-ID | <kq9bvc$i1g$3@speranza.aioe.org> |
| In reply to | #3553 |
Victor Porton wrote: > Rui Maciel wrote: > >> Victor Porton wrote: >> >>> Rui Maciel wrote: >>> >>>> Victor Porton wrote: >>>> >>>>> Rui Maciel wrote: >>>>> >>>>>> Victor Porton wrote: >>>>>> >>>>>>> But what is the best way to do this if we want a MULTILEVEL >>>>>>> associative array? (indexed by first key "a", then by key "b", etc.) >>>>>>> >>>>>>> I want to discuss the most elegant, short, and practical solution >>>>>>> for this kind of problems. >>>>>> >>>>>> I don't know if it's the most elegant, but if you wish to have >>>>>> multiple keys map to a value then you can resort to a tuple >>>>>> containing both keys as your map's key. >>>>>> >>>>>> That approach is very common. For example, with the "dictionary of >>>>>> keys" matrix data structure, the matrix elements are stored in a >>>>>> key:value pair whose key is a (row, column) tuple. >>>>> >>>>> It seems you have misunderstood me. I ask about forming a *multilevel* >>>>> associative array like: >>>>> >>>>> [1:[2:[[a:1, b:2, c:3],...]]] >>>>> >>>>> where "1" a value of the key "a", "2" is a value of the key "b", etc. >>>>> >>>> >>>> What do you mean by "multi-level"? For example, from your example, by >>>> multi- level do you mean that in order to access the value in the a:1 >>>> key value pair, the map goes something like: >>>> >>>> example_map[1][2][a] == 1 ? >>> >>> Yes, well almost: >>> >>> example_map[1][2] (without [a]) >> >> Just to get things straight, you expect an outcome similar to the >> following pseudo-ish code? >> >> example_map[1][2] == 1 > > example_map[1][2] == [a:1, b:2, c:3] > >> Rui Maciel Oh, sorry Rui Maciel, I've falsely accused you for an error. Everything you have written is true. -- Victor Porton - http://portonvictor.org
[toc] | [prev] | [next] | [standalone]
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2013-06-24 20:36 +0300 |
| Subject | Solved: Generating multi-level associative arrays |
| Message-ID | <kqa039$hc4$1@speranza.aioe.org> |
| In reply to | #3516 |
Victor Porton wrote: > Suppose we have an array each element of which is an associative array: > > [[a:1, b:2, c:3], ...] > > I want to create an associative array out of it, indexed by values of some > key (such as the key "a"): > > [1:[[a:1, b:2, c:3], ...], ...] > > (a value "1" of the key may be met more than once, thus with the value "1" > of the key "a" is associated an array [[a:1, b:2, c:3], ...] not just > [a:1, b:2, c:3]. > > It is easy to program in any modern language. > > But what is the best way to do this if we want a MULTILEVEL associative > array? (indexed by first key "a", then by key "b", etc.) > > I want to discuss the most elegant, short, and practical solution for this > kind of problems. > > We could even write practically usable libraries of real code to do this > kind of things. > > Note that in fact I use PHP. I've written PHP code for this: http://portonsoft.wordpress.com/2013/06/24/php-multilevel-array/ -- Victor Porton - http://portonvictor.org
[toc] | [prev] | [standalone]
Back to top | Article view | comp.programming
csiph-web