1

I know there are dynamically sized arrays, but I need a data structure that can remove elements from the middle cheaply. Using pop() with a dynamically sized array should require a shift of every element coming after by one, which would be way too expensive. Is there an industry standard way of doing this?

Alternatively I can switch the element I want to delete with the last element in a dynamic array and then pop() the last element, because the order of my list doesn't matter.

2

This is a library for organizing an unordered key set with delete capability.

https://github.com/rob-Hitchens/UnorderedKeySet

It is an implementation of the Mapped Structs with Delete-enabled Index technique in the SE page Richard linked to.

The library deals with the keys only. Store structs in a mapping to handle additional fields.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.