Forum Navigation
Nested Hashmap
Posted: 09/09/08 15:29:01 Modified: 09/09/08 15:29:21I try to include Hashmap as a value into another Hashmap, which works fine so far. This is the declaration:
alias hm.HashMap!(uint, float, Container.hash, Container.reap, Container.Chunk) myListMap; alias hm.HashMap!(uint, myListMap, Container.hash, Container.reap, Container.Chunk) myListMap2; myListMap tmp_map = new myListMap(); myListMap2 list2 = new myListMap2();I can add myListMap to myListMap2. The problem starts, when I want to append values to myListMap. My idea was to retrieve the myListMap Hashmap from myListMap2 with a list2_key1 and assign it to a temporary Hashmap of type myListMap. Then append the new key, value pair and reassign the tmp_map to the myListMap2 again.
tmp_map = list2[list2_key1]; tmp_map[tmp_map_key2] = value; list2[list2_key1] = tmp_map;All this is inside a class function and all Hashmaps are globally available in the class. tmp_map was made available globally, because I dont wanted to instantiate tmp_map with each call of the function. Therefore I made it globally available and added:
tmp_map.clearat the beginning of the function. But unfortunately this brings rather weird results.
What I would like is to have is a data structure like this, where I can add new list_key/value pairs and and new tmp_map_key/value pairs.
-------------------------------------------------------------- list_key1 => tmp_map_key1 | tmp_map_key2 | tmp_map_key3 .. tmp_map_value1 | tmp_map_value2 | tmp_map_value3 .. -------------------------------------------------------------- list_key2 => tmp_map_key1 | tmp_map_key2 | tmp_map_key3 .. tmp_map_value1 | tmp_map_value2 | tmp_map_value3 .. -------------------------------------------------------------- list_key3 => tmp_map_key1 | tmp_map_key2 | tmp_map_key3 .. tmp_map_value1 | tmp_map_value2 | tmp_map_value3 .. --------------------------------------------------------------How do I accomplish that? What exactly does the clear function of the Hashmap? Can anyone give me a advise how to solve that?
best regards Lars
Some thoughts about switching from PHP to D: http://www.lars-kirchhoff.de/go/journal/section/from-php-to-d/