Hey guys, I used HashMap before. Now I want to use preupgrade and postupgrade to copy the data in userMap to userTrie. I found that Inter has a toList function and Trie has fromList function. Does anyone know how to use these two functions? Or is there any other way? thx.
var userMap = HashMap.HashMap<Text, User>(1, isEq, Text.hash);
stable var userTrie: Trie.Trie<Text, User> = Trie.empty();
system func preupgrade() {};
system func postupgrade() {};
My steps are as follows
step 1. I used dfx deploy to deploy the code, including preupgrade() code.
step 2. I add some data to userMap.
step 3. Then I used dfx deploy again to deploy the code, but the data in userMap was not copied to userTrie.
However, if I delete the code of preupgrade() in step 2, and then execute step 3, then the data in userMap can be copied to userTrie.
I think preupgrade() is executed every time I update the canister. In step 1, I have deployed it, and in step 3, it should be executed when I deploy it again.