Looking for a datastructure that logically represents a sequence of elements keyed by unique ids (for the purpose of simplicity let's consider them to be strings, or at least hashable objects). Each element can appear only once, there are no gaps, and the first position is 0.
The following operations should be supported (demonstrated with single-letter strings):
insert(id, position)- add the element keyed byidinto the sequence at offsetposition. Naturally, the position of each element later in the sequence is now incremented by one. Example:[S E L F].insert(H, 1) -> [S H E L F]remove(position)- remove the element at offsetposition. Decrements the position of each element later in the sequence by one. Example:[S H E L F].remove(2) -> [S H L F]lookup(id)- find the position of element keyed byid.[S H L F].lookup(H) -> 1
The naïve implementation would be either a linked list or an array. Both would give O(n) lookup, remove, and insert.
In practice, lookup is likely to be used the most, with insert and remove happening frequently enough that it would be nice not to be linear (which a simple combination of hashmap + array/list would get you).
In a perfect world it would be O(1) lookup, O(log n) insert/remove, but I actually suspect that wouldn't work from a purely information-theoretic perspective (though I haven't tried it), so O(log n) lookup would still be nice.