Skip to content

Conversation

AndriySvyryd
Copy link
Member

Fixes #31142
Fixes #19361

Implementation copied from https://github.com/dotnet/corefxlab/blob/archive/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/OrderedDictionary.cs until it's included in the framework.

For reference, these are its perf characteristics:

Operation Dictionary<K,V> SortedDictionary<K,V> SortedList<K,V> OrderedDictionary<K,V>
this[key] O(1) O(log n) O(log n) or O(n) O(1)
this[index] n/a n/a n/a O(1)
Add(key,value) O(1) O(log n) O(n) O(1)
Remove(key) O(1) O(log n) O(n) O(n)
RemoveAt(index) n/a n/a n/a O(n)
ContainsKey(key) O(1) O(log n) O(log n) O(1)
ContainsValue(value) O(n) O(n) O(n) O(n)
IndexOf(key) n/a n/a n/a O(1)
Insert(index,key,value) n/a n/a n/a O(n)
Space efficiency good worst medium good
Insert/Remove sorted data n/a O(log n) O(n) n/a
From sorted data n/a ? better? n/a

@AndriySvyryd AndriySvyryd requested a review from a team October 22, 2023 03:35
@roji
Copy link
Member

roji commented Oct 22, 2023

Implementation copied from https://github.com/dotnet/corefxlab/blob/archive/src/Microsoft.Experimental.Collections/Microsoft/Collections/Extensions/OrderedDictionary.cs until it's included in the framework.

Isn't it already in the framework, or am I missing something?

@AndriySvyryd
Copy link
Member Author

Isn't it already in the framework, or am I missing something?

Only the non-generic version. dotnet/runtime#24826

@roji
Copy link
Member

roji commented Oct 22, 2023

Oh interesting...


/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual SortedDictionary<(string, string?), Table> Tables { get; }
= new();
public virtual Dictionary<(string, string?), Table> Tables { get; } = new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I run code cleanup again? ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to run it many times for 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve RuntimeModel building performance ForeignKeys, Keys and Indexes on Property should have a strong order defined
3 participants