-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OrderedDictionary #103309
Add OrderedDictionary #103309
Conversation
Note regarding the
|
1 similar comment
Note regarding the
|
@stephentoub @terrajobst public void Move(int oldIndex, int newIndex);
public void Stort(IComparer<TValue> comparer); |
Adding some kind of sorting functionality would be useful, but ideally that should be solved for IList in general, cf. #76375 |
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
This rewrites the core of the type to be based on a custom data structure rather than wrapping Dictionary and List. The core structure is based on both Dictionary in corelib and the OrderedDictionary prototype in corefxlab. This also adds missing TryAdd, Capacity, EnsureCapacity, and TrimExcess members for parity with Dictionary, and fixes debugger views for the Key/ValueCollections.
e7e543c
to
a4dca87
Compare
@eiriktsarpalis, please take another look when you get a chance. I redid the guts based on the feedback to prioritize enumeration. It's based on a combination of approaches taken by |
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/ThrowHelper.cs
Outdated
Show resolved
Hide resolved
...s/System.Collections/tests/Generic/OrderedDictionary/OrderedDictionary.Generic.Tests.Keys.cs
Outdated
Show resolved
Hide resolved
/ba-g all failures are known |
@stephentoub Thank you very much for doing this! It's fantastic that we can finally use generic OrderedDirectiory out of the box without using 3rd-party NuGet packages or implementing it from scratch. |
// to record the newly updated indices. | ||
for (i = _count - 1; i >= index; --i) | ||
{ | ||
entries[i + 1] = entries[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance we could perf improvement if the shifting of the entries array used block copying?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. But we still need to walk the entries individually to fix up the chains. We can more easily experiment with it once it's in a daily.
Closes #24826