Let’s say I create hashmap where every key is assigned to another hashmap, and I populate this with some values:
var x1 = H.HashMap<Text, Nat>(2, Text.equal, Text.hash); var x2 = H.HashMap<Text, Nat>(2, Text.equal, Text.hash); var map = H.HashMap<Text, H.HashMap<Text, Nat>>(10, Text.equal, Text.hash); x1.put("a1", 50); x2.put("a1", 100); map.put("2021-09-22", x1); map.put("2021-09-23", x2);
How do I go about maintaining the state of this variable? I understand that I’m not able to declare the map variable as stable, and I’ve taken a look at pre-upgrade and post-upgrade functions, but I’m having trouble converting this hashmap into the correct kind of stable list.
So far I’ve tried iterating through that map variable in an attempt to write it to a list of type [ (Text, [ (Text, Nat) ] ) ], but I haven’t had any success so far. I’m not used to declaring list sizes in advance, so this is giving me some trouble. Is there an easy way to do this, or is there a different way I should be thinking about this?