How to use nested map in Move #63
-
Asked by How do I create nested maps in Move? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can have nested table (which is map in Aptos) in your struct like this
|
Beta Was this translation helpful? Give feedback.
-
I don't want to open a new discussion, so I ask here:
Then I run
What to do? How do I add the required ability drop? If I remove the drop ability from the struct it does work but then I get errors all over my codebase where the struct is used because it needs to have that ability |
Beta Was this translation helpful? Give feedback.
There are three types of "Map-like" data structures in Aptos:
Table
SmartTable
andSimpleMap
There are tradeoffs for each on gas costs, and ease of use.
It depends on your use case.
I did a segment on this on twitter https://x.com/Greg_Nazario/status/1760809623194677725?s=20
But the tl;dr:
SimpleMap
is based in a vector, it doesn't scale > 10k, so if you want a large set you should stay away from it. Every lookup may iterate through the whole map.SimpleMap
can't be nested.Table
is useful, but it's not iterable. So, if you need to iterate over multiple values, and you don't know what they are ahead of time, I would not use it.SmartTable
is iterable, and generally more efficient thanTable