I'm puzzled what is more efficient to use, from the point of gas consumption (storage and execution), dynamic array or the mapping and element counter.
To be more clear, I'm not asking the basic data structure usage paradigms that we all should know, nor about pros and cons that each have, rather I want to know what is more gas efficient.
Let me give you an example in a sort of pseudo code:
contract DataStorage {
//mapping and data counter
mapping (uint256 => uint256) sequentialData1;
uint256 sequentialData1Counter;
//dynamic array
uint256[] sequentialData2;
function addDataToMapping(uint256 _newData) {
sequentialData1[sequentialData1Counter++] = _newData;
}
function addDataToDynamicArray(uint256 _newData) {
sequintialData2.push(_newData);
}
}
Don't think about deleting elements and so on, let's say I just want to add new data to array and be able to access them by index.