Closed NN--- closed 4 years ago
Ideas for HashSet
Remember that TryGetValue is meant to return the value that was inserted.
I'm thinking that it can be implemented by creating a copy of the HashSet and then using InsersectWith.
What do you mean ? Isn't TryGetValue simply call to Contains and return the value if exists ?
TryGetValue()
{
if (hashSet.Contains(equalValue)) { actualValue = equalValue; return true; }
actualValue = default(T);
return false;
}
Nope, it returns the value that was inserted, not the value that was used to check. Yes, those values are equal (according to the comparer), however they might still not be the same.
I see. Technically you can get the internals using reflection since the implementation won't change :) Iterating over HashSet is better than copying, since copying requires iterating anyway, no ?
I think copying is better. The copy constructor of the hashset has a path dedicated to copying a hashset that would be better than copying to array or using GetEnumerator. Similarly IntersectWith has a fast path for HashSet intersecting another HashSet.
I suppose I should test and see what is actually faster.
Let's do anything simple and then optimize.
Nuget Version 3.1.1
Missing .NET 4.7.2 targeting, #114
https://docs.microsoft.com/en-us/dotnet/framework/whats-new/#core-472 https://docs.microsoft.com/en-us/dotnet/standard/frameworks