in reply to Using a hash for an ordered set can make sense
While it looks like a lot of work to build a new array from scratch, it is a lot less work than it is to do a lot of manual manipulations of the array, each of which involve moving around large chunks of the existing array.
This observation will allow you to fix the vast majority of performance problems arising from having to do a lot of detail manipulation of arrays. But there are a very small number of programs which simply must do a lot of inserting and deleting which cannot be fixed. The odds are very small that you have one of those. This is so even if you don't see offhand how to fix the program to avoid the issue. (It takes some experience to find the fixes.) But for that infinitesmal remainder, I would recommend that you tie the array to a data structure (eg DB_File's BTREE implementation) that has slower accessing but allows inserts and deletes to be done much faster.
Voila! Works like magic! (In fact magic what does makes tie work behind the scenes...)
|
---|