in reply to Testing if an array contains a value and then deleting it in most efficient way
Deleting from the middle of an array is inherently slow, since all the subsequent elements need to be shifted. Locating elements is slow too.
Is the data sorted by the search criteria?
If so, the item can be located using a binary search which is much faster than a linear search.
Can you use a hash indexed by the search criteria.
Locating and deleting the element would become really cheap.
If you're stuck with an array, you might want to consider undefing the element instead of deleting it. Just skip the undefs when it's time to save the structure.
|
|---|