Does “delete” reorganise the array in solidity?
If I have an array of x elements 1 to 10, I delete the 5 index, then what happens? I have an array of 10 items from 0 to 9, or I have 0 to 10 without the 5 index?
Jan 15, 2022, 10:52 AM
is it an ordinated array?
if order is not important, you can copy the last element to the index i and then call pop()
Jan 15, 2022, 10:57 AM
Yes, because I have to use it in a for cycle
Jan 15, 2022, 10:58 AM
then is a bit more complex
Jan 15, 2022, 10:59 AM
I wonder if, reorganising the array with a long size, would be a performance/gas fee issue
Jan 15, 2022, 10:59 AM
of course high gas cost
Jan 15, 2022, 10:59 AM
Or basically if it’s better to keep the main array and add like a “inactive” variable
Jan 15, 2022, 10:59 AM
if you keep the 0 value the for cycle wil literate on it too
Jan 15, 2022, 11:00 AM
But in this case I have to call 0/null which corresponds also to unfound elements?
Or simply a for with
i to length-1 , check if element[i] == 0 can work, then continue iterating to length-1, could be a bottleneck or can work?
i to length-1 , check if element[i] == 0 can work, then continue iterating to length-1, could be a bottleneck or can work?
Jan 15, 2022, 11:02 AM
it will always iterate on it
to check if it is == 0, you must iterate on it
you could try to check inside the iteration before
so
if(element[i+1]==0) i++
if(element[i+1]==0) i++
of course check if you are on the last element
Jan 15, 2022, 11:04 AM
Ok I’ll try doing like that, thanks
Jan 15, 2022, 11:05 AM