0

if I want to have a mapping both ways (getting value by key and key by value) is it the most efficient approach to simply initialize 2 mappings pointing in the opposite directions?

mapping(uint64 => address) public frontEndTags;
mapping(address => uint64) public frontEndIds;

Thank you, Jan

1 Answer 1

0

In general, this is a normal solution, but in order to talk about "efficiency", it's need to know the whole problem that you want to solve. If you update them in parts with each transaction, then most likely everything will be fine. But if, for example, you need a one-time or periodic batch upload of several thousand values to these mappings in public Ethereum, then it will be very expensive.

1
  • There will be only a few values in those mappings (probably less than 10) so 2 mappings should be fine. Thank you :)
    – Jan Beneš
    Commented Jan 7, 2022 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.