I am looking for a list-like data structure with the following properties:
- Generic, i.e.,
DataStructure<T>, whereTis generic - Multiple different instances of
Twhich are considered equal byIComparable<T>must be allowed to be present in the list at the same time; their order can be arbitrary (even change), but they must come after "smaller" instances ofTand before "larger" instances ofT O(log(n))insertion time complexity (or faster)O(log(n))retrieval time complexity (or faster)- Possibility to access the first/last element with
O(1)time complexity - Possibility to access the predecessor/successor of an element with
O(1)time complexity - Available without the use of additional libraries
I do not care about removal time complexity since elements only need to be deleted very rarely. I also do not care about space complexity.
I know that there is no data structure which fulfills all properties, but the ones from the BCL (which look like they could do what I need at first glace) seem to have too many disadvantages:
SortedSet<T>does not allow multiple instances which are considered the same byIComparable<T>(2) and does not have predecessor/successor functions (6)SortedSet<T, List<T>>(with only one "representative" indexing instance ofT) would require quite some additional (ugly) code, and there is still no predecessor/successor function (6)SortedList<T, T>is too slow for insertion (3)SortedDictionary<T, T>does not allow multiple instances which are considered the same byIComparable<T>(2) and does not allow accessing the first/last element directly (5), nor does it have predecessor/successor functions (6)- Inheriting from
List<T>and keeping it sorted would possibly be an option, but I'd rather use something that is built-in (7) due to the implementation effort and the potentially poor performance
Am I overlooking something? There seem to be no other relevant data structures for my use case (I looked here and here, among others). Is there another data structure which I did not consider?