-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Collections
Milestone
Description
Background and motivation
We added GetAlternateLookup() to many collection types, including Dictionary<TKey, TValue> and HashSet<T>. We should add it to SortedSet<T> as well, for symmetry. In my case, I often use SortedSet<string> over HashSet<T> because I'm persisting data to disk and I'd like to have a stable order to make diffs less jarring.
API Proposal
namespace System.Collections.Generic;
public partial class SortedSet<T>
{
public readonly struct AlternateLookup<TAlternate>
{
public SortedSet<T> Set { get; }
public bool Add(TAlternate item);
public bool Contains(TAlternate item);
public bool Remove(TAlternate item);
public bool TryGetValue(TAlternate equalValue, [MaybeNullWhen(false)] out T actualValue);
}
public AlternateLookup<TAlternate> GetAlternateLookup<TAlternate>();
public bool TryGetAlternateLookup<TAlternate>(out AlternateLookup<TAlternate> lookup);
}API Usage
var set = new SortedSet<string>() { "Immo", "Landwerth" };
var lookup = set.GetAlternateLookup<ReadOnlySpan<char>>();
var span = "Immo".AsSpan();
lookup.Contains(span);Alternative Designs
No response
Risks
No response
PaulusParssinen
Metadata
Metadata
Assignees
Labels
api-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementationarea-System.Collections