The behavior Jason is referring to is in the "getSlice" method. That iterates down the dimensions of a map, creating intermediate levels as needed. The method I pointed you to is used to fetch a value in the final level, after getSlice has been used to get there.
Edit: here's a little test program.
Code:
int [int,int] test;
print( "test contains 1 = " + test contains 1 );
print( "test[1] contains 2 = " + test[1] contains 2 );
print( "test contains 1 = " + test contains 1 );
print( "test[1,2] = " + test[1,2] );
print( "test contains 1 = " + test contains 1 );
print( "test[1] contains 2 = " + test[1] contains 2 );
foreach key1, slice1 in test
{
print( "test[" + key1 + "] = " + slice1 );
foreach key2, value in test[ key1 ]
{
print( "test[" + key1 + "," + key2 + "] = " + value );
}
}
and here's how it operates with the current code:
> mmaps
test contains 1 = false
test[1] contains 2 = false
test contains 1 = true
test[1,2] = 0
test contains 1 = true
test[1] contains 2 = true
test[1] = 2
test[1,2] = 0
Notice that as soon as we referenced test[1], that slice was created. When we referenced test[1,2], the second slice was created. And iterating over the multi-dimensional map at the end, we see that test[1] has index 2 in it, and test[1,2] has value 0 in it.
I removed the line from getValue() as I suggested, compiled, and reran the test.
> mmaps
test contains 1 = false
test[1] contains 2 = false
test contains 1 = false
test[1,2] = 0
test contains 1 = true
test[1] contains 2 = false
Notice that referencing test
did NOT create that index. Referencing test[1,2] found the default value and did create the intermediate layer test[1] but did not create element test[1,2].
Edit 2: I changed the foreach loop at the end:
Code:
foreach key1 in test
{
print( "test[" + key1 + "] = " + test [key1] );
foreach key2 in test[ key1 ]
{
print( "test[" + key1 + "," + key2 + "] = " + test[key1,key2] );
}
}
and reran it:
> mmaps
test contains 1 = false
test[1] contains 2 = false
test contains 1 = false
test[1,2] = 0
test contains 1 = true
test[1] contains 2 = false
test[1] = aggregate int [int]
Now you can see if intermediate layer there at test[1]. It's empty, since when we foreach over it we find nothing.
Edit n: OK, last demo. I modify the test program thus:
Code:
int [int,int] test;
void pmap()
{
foreach key1 in test
{
print( "test[" + key1 + "] = " + test[key1] );
foreach key2 in test[ key1 ]
{
print( "test[" + key1 + "," + key2 + "] = " + test[key1,key2] );
}
}
}
print( "test contains 1 = " + test contains 1 );
print( "test[1] contains 2 = " + test[1] contains 2 );
print( "test contains 1 = " + test contains 1 );
print( "test[1,2] = " + test[1,2] );
print( "test contains 1 = " + test contains 1 );
print( "test[1] contains 2 = " + test[1] contains 2 );
pmap();
test[1,2] = 3;
print( "test contains 1 = " + test contains 1 );
print( "test[1] contains 2 = " + test[1] contains 2 );
pmap();
and get this:
> mmaps
test contains 1 = false
test[1] contains 2 = false
test contains 1 = false
test[1,2] = 0
test contains 1 = true
test[1] contains 2 = false
test[1] = aggregate int [int]
test contains 1 = true
test[1] contains 2 = true
test[1] = aggregate int [int]
test[1,2] = 3
...which looks reasonable to me.