I'm looking for a data structure which would efficiently solve Order-maintenance problem. In the other words, I need to efficiently
- insert (in the middle),
- delete (in the middle),
- compare positions of elements in the container.
I found good articles which discuss this problem:
- Two Algorithms for Maintaining Order in a List,
- Two Simplified Algorithms for Maintaining Order in a List.
The algorithms are quite efficient (some state to be O(1) for all operations), but they do not seem to be trivial, and I'm wondering if there is an open source C++ implementation of these or similar data structures.
I've seen related topic, some simpler approaches with time complexity O(log n) for all operations were suggested, but here I'm looking for existing implementation.
If there was an example in some other popular languages it would be good too, this way I would be able at least to experiment with it before trying to implement it myself.
Details
I'm going to
- maintain a list of pointers to objects,
- from time to time I will need to change object's order (delete+insert),
- given a subset of objects I need to be able to quickly sort them and process them in correct order.
Note
The standard ordering containers (std::set, std::map) is not what I'm looking for because they will maintain order for me, but I need to order elements myself. Similar to what I would do with std::list, but there position comparison would be linear, which is not acceptable.