I am looking for a list-like data structure with the following properties:
DataStructure<T>
, where T
is generic T
which are considered equal by IComparable<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 of T
and before "larger" instances of T
O(log(n))
insertion time complexity (or faster) O(log(n))
retrieval time complexity (or faster) O(1)
time complexity O(1)
time complexity 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 by IComparable<T>
(2) and does not have predecessor/successor functions (6) SortedSet<T, List<T>>
(with only one "representative" indexing instance of T
) 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 by IComparable<T>
(2) and does not allow accessing the first/last element directly (5), nor does it have predecessor/successor functions (6) 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?
如果您愿意放松5和6,则可以使用TreeMap
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.