Provide ImmutableSortedSetArray<T> an ImmutableSortedSet based on array not on tree
Rational
ImmutableSortedSet
- property Item[Int32] has compexity in O(Log(N))
- We can't have an "equivalent" ImmutableArray without make a copy
In the ImmutableCollections framework, we already have the same type of choice for our data structures.
I think to the distinction between ImmutableArray
With this structure we could have:
- property Item[Int32] with O(1) complexity
- We can have an property ToImmutable without any copy make (call of the internal ImmutableArray constructor).
Usage
Very ofen we want to have the garanty (by type) than the incomming Array T[] is sorted to call safely BinarySearch. Of course we could used the ImmutableSortedSet
Another use case come when we have to rely on native API (eg Interpolation API) when we want a sorted Array double* in input. With an ImmutableSortedSetArray
Could you provide an ImmutableSortedSet based on a Array ?
:memo: Several of the use cases for this would be partially mitigated by dotnet/runtime#14477.
After discussing this with @ianhays we think that it is not valuable adding a new API which would be a copy of an existing API but with a different implementation. First of all this would confuse costumers, second of all any one could implement this by using our interfaces. So we really think that what is suggested here is to change the implementation to have a better performance, something like proposed in dotnet/runtime#14477.
Thanks for the answer 😀. But with this kind of thought we'd never have had the 2 distincts implementations ImmutableArray