Hot answers tagged

2

Nothing like that exists because the obvious solution would involve considerable, variable gas cost to reorganize data at rest. There are patterns that combine mappings and arrays to create iteratable sets with random access. If it is to be sorted or organized in any particular order then one needs to code for that as well. Have a look over here for some ...


1

It always depends on your needs. The biggest difference is that you can't iterate over a mapping. So if you store two entries (key => value) in a mapping, there is no way to get the values without knowing the keys. In your example, it also depends on your needs. If you only want to access the answers based on known key (so for example a function which ...


1

I think that this should work. pragma solidity >=0.7.0 <0.9.0; contract MyContract { function foo(uint i, uint j) external pure returns (uint) { uint8[16] memory x = [10, 2, 6, 42, 19, 5, 4, 36, 6, 6, 5, 5, 5, 46, 4, 4]; return x[i] + x[j] * 12; } }


Only top voted, non community-wiki answers of a minimum length are eligible