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

Jan Beneš
  • 569
  • 1
  • 7
  • 14

1 Answers1

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.

Mad Jackal
  • 1,195
  • 2
  • 5
  • 8
  • There will be only a few values in those mappings (probably less than 10) so 2 mappings should be fine. Thank you :) – Jan Beneš Jan 07 '22 at 08:18