[DGD] [Melville] non-static mappings
Shevek
shevek at btinternet.com
Wed Feb 6 17:57:59 CET 2002
>Ok, that was totally unrelated to what you asked, but let me assure
>you that 'map[key] = nil' has the same effect of 'map -= ({ key })'.
>
>Please, don't let me post before having had my coffee, next time?
>
>Erwin. ;-)
>--
>Erwin Harte <harte at xs4all.nl>
Had to go and check this out, mainly because it's bugging me as to where I
picked up the wrong idea about it in the first place.
Here's some test code:
string *testarr,*testkey;
mixed testmix;
string *keys;
int i;
/* testmap is declared outside the function as 'mapping testmap' */
/* So that its value is saved with the object */
testmap=([ ]);
testarr=({"test1","test2","test3","test4","test5","test6","test7","test8","test9",});
testkey=({"key1","key2","key3"});
/* Populate mapping */
for(i=0;i<sizeof(testkey);i++){
testmap[testkey[i]]=testarr[i*3..i*3+2];
}
keys=map_indices(testmap);
for(i=0;i<sizeof(keys);i++){
message(keys[i]);
}
message("\n");
testmix=map_values(testmap);
message("Number of values:" + sizeof(testmix) + "\n");
for(i=0;i<sizeof(testmix);i++){
message("Type for value under " + keys[i] + "=" +
typeof(testmap[keys[i]]) + "\n");
}
message("\n\n");
/* testmap-=({testkey[1]});*/
testmap[testkey[1]]=nil;
keys=map_indices(testmap);
for(i=0;i<sizeof(keys);i++){
message(keys[i]);
}
message("\n");
testmix=map_values(testmap);
message("Number of values:" + sizeof(testmix) + "\n");
for(i=0;i<sizeof(keys);i++){
message("Type for value under " + keys[i] + "=" +
typeof(testmap[keys[i]]) + "\n");
}
message("\n");
save_object("/usr/Shevek/mapping.test");
}
Here are the results:
key1key2key3
Number of values:3
Type for value under key1=5
Type for value under key2=5
Type for value under key3=5
key1key3
Number of values:2
Type for value under key1=5
Type for value under key3=5
And from the save file:
testmap
([2|"key1":({3|"test1","test2","test3",}),"key3":({3|"test7","test8","test9",}),])
Both methods produce exactly the same results.
Ie Both remove all values associated under the key and the key from the
mapping. Neither produced anything unexpected in the save file.
Now if I could just figure out why I thought differently :>
Cheers,
Shevek
_________________________________________________________________
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list