www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Associative multidimensional Arrays

reply "MaB" <nitramlxl googlemail.com> writes:
Hi!

I want to bulid up a IndexArray with a structure like this (PHP 
code):
<code>
$arrIndex = array(
  "A" => array(
           "B" => array()
         ),
  "B" => array(
           "B" => array("C" => array())
         )

);
</code>
The Keys are of Type string and the values can be arrays with the 
same structure.
The Array-Depth has to be variable..
Is there a way in D to make it possible? I am trying it now since 
hours :(

Greetings
Jun 12 2013
next sibling parent "gedaiu" <szabobogdan yahoo.com> writes:
Hi,

Please look at this thread. You might find your answer there:

http://forum.dlang.org/thread/vphniyxyvgsiazuttona forum.dlang.org

Bogdan

On Wednesday, 12 June 2013 at 20:20:09 UTC, MaB wrote:
 Hi!

 I want to bulid up a IndexArray with a structure like this (PHP 
 code):
 <code>
 $arrIndex = array(
  "A" => array(
           "B" => array()
         ),
  "B" => array(
           "B" => array("C" => array())
         )

 );
 </code>
 The Keys are of Type string and the values can be arrays with 
 the same structure.
 The Array-Depth has to be variable..
 Is there a way in D to make it possible? I am trying it now 
 since hours :(

 Greetings
Jun 12 2013
prev sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 06/12/2013 01:20 PM, MaB wrote:
 Hi!

 I want to bulid up a IndexArray with a structure like this (PHP code):
 <code>
 $arrIndex = array(
   "A" => array(
            "B" => array()
          ),
   "B" => array(
            "B" => array("C" => array())
          )

 );
 </code>
 The Keys are of Type string and the values can be arrays with the same
 structure.
 The Array-Depth has to be variable..
 Is there a way in D to make it possible? I am trying it now since hours :(

 Greetings
Pretty complex but I think this is it: import std.stdio; import std.array; struct Node { Node[][string] children; } void main() { Node[] table; table ~= Node(); table.back.children["A"] ~= Node(); table.back.children["A"].back.children["B"] ~= Node(); writeln(table); } Ali
Jun 12 2013
parent "MaB" <nitramlxl googlemail.com> writes:
Thx Ali!

You pushed me in the right directoin :)
Jun 13 2013