in regards to contracts, in general, is it considered more expensive
to add / remove from an array continually,
or instead use an append-only array and simultaneously use
a mapping to track the validity of each array item?
eg: an array of active users.
I could continually add / remove from the array as users come and go,
or I could only add new users to the array, and track their "active" and "added"
statuses to help filter the array.
I suspect it is more expensive with only an array, but I want to make sure.
Oct 9, 2020, 6:17 PM
Thx. I want to maintain a mapping(address => MyStruct[])
As structs in this mapping become invalid I have to either remove them or mark them another way, eg: another mapping
As structs in this mapping become invalid I have to either remove them or mark them another way, eg: another mapping
or I could have a "valid" key on the struct... that's probably easiest
yeah that's what i'm wondering. To Delete the struct from the array would mean creating a whole new array, and I suspected that would be expensive.
ah, I see there is a DELETE operator for arrays, and then I just shift everything over to fill the gap.
Oct 9, 2020, 6:39 PM
move the last element into the deleted position
otherwise it will cost in some scenarios
if you need to preserve the order of the elements - use a linked list
Oct 9, 2020, 6:40 PM
ah for sure, that's much easier.
and nope, order doesn't matter 👍
and nope, order doesn't matter 👍
Oct 9, 2020, 6:40 PM