Implement Enumerable.ToHashSet()#13726
Conversation
| <Import Project="..\dir.props" /> | ||
| <PropertyGroup> | ||
| <AssemblyVersion>4.1.2.0</AssemblyVersion> | ||
| <AssemblyVersion>4.2.0.0</AssemblyVersion> |
There was a problem hiding this comment.
I gather it's ++minor on additions of public members. Am I correct?
| public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TElement> elementSelector) { throw null; } | ||
| public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) { throw null; } | ||
| public static System.Collections.Generic.HashSet<TElement> ToHashSet<TElement>(this System.Collections.Generic.IEnumerable<TElement> source) { throw null; } | ||
| public static System.Collections.Generic.HashSet<TElement> ToHashSet<TElement>(this System.Collections.Generic.IEnumerable<TElement> source, System.Collections.Generic.IEqualityComparer<TElement> comparer) { throw null; } |
There was a problem hiding this comment.
@weshaggard, does any specialization need to be done for netstandard vs netcoreapp?
There was a problem hiding this comment.
We had been surrounding new APIs with #if netcoreapp11 in the ref assemblies and tests were separated out into conditionally included _Foo_Tests.netcoreapp1.1.cs files, e.g. see #12226. Is that not necessary anymore?
There was a problem hiding this comment.
I'll assume it still is, and update accordingly.
There was a problem hiding this comment.
Yes it is still necessary for now. Please add a netcoreapp11 build configuration for these new APIs.
|
Implementation and tests LGTM. Thanks. |
| return d; | ||
| } | ||
|
|
||
| public static HashSet<TElement> ToHashSet<TElement>(this IEnumerable<TElement> source) => source.ToHashSet(null); |
There was a problem hiding this comment.
Should the generic parameter be named TSource to match the naming used by ToList, ToArray, and ToDictionary? TElement is only used for the ToDictionary overloads with an elementSelector.
There was a problem hiding this comment.
It was indeed ToDictionary that steered me wrong. Will change to TSource.
93a0210 to
3a47a40
Compare
eae8abe to
c46c1ca
Compare
|
I'm missing something silly here. I've got ToHashSetTests.netcoreapp1.1.cs only coming in if What am I missing here? |
|
Unfortunately it looks like Jenkins deleted all of the logs for that since the links all 404 for me. @dotnet-bot Test this please |
|
implementation and tests LGTM. |
|
@mellinoe the error is "'IEnumerable' does not contain a definition for 'ToHashSet'…" and others that suggest that tests\ToHashSetTests.netcoreapp1.1.cs is being compiled against a version of System.Linq that didn't have |
c46c1ca to
50f4aa3
Compare
|
@dotnet-bot test Innerloop Windows_NT Debug Build and Test |
|
@JonHanna check out the changes here: ericstj@a2274f9 |
| <ItemGroup> | ||
| <Project Include="System.Linq.csproj" /> | ||
| <Project Include="System.Linq.csproj"> | ||
| <TargetGroup>netcoreapp1.1</TargetGroup> |
There was a problem hiding this comment.
Can you please flip and make netcoreapp1.1 the default and the netstandard16 the secondary configuration?
|
Ah. I had And now it at least builds locally (though that was true of some other problematic pushes) so assuming it builds correctly here I'll sit down and learn what was going on, so I'll actually have some understanding the next time. Now we play the waiting game… Thanks. |
|
@ericstj locally my coverage report shows <ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp1.1'">
<Compile Include="ToHashSetTests.netcoreapp1.1.cs" />
</ItemGroup>As well? |
|
@dotnet-bot test this please. |
|
@dotnet-bot test code coverage |
|
@JonHanna can you build |
|
WRT to coverage, I think you must be looking at the wrong report. Make sure to look at coverage for the netcoreapp1.1 run of the test. |
5e0561b to
cff7ce9
Compare
|
Thanks that packages step goes some way to explain how things hang together and be less "magic just happens". |
|
If you don't specify a project MSBuild picks the one file with a *proj extension, which means it doesn't pass any properties (like TargetGroup). If you want to run it on all configurations, specify the builds file. EG: |
|
Things are coming up green. Thanks again for your help, @ericstj |
cff7ce9 to
b2991d9
Compare
Closes #2323 A straight-forward implementation, forgoing any optimisations. HashSet's constructor already has some for some cases, and others could be wasteful unless not just the number of elements, but the number of elements that are distinct in terms of the equality comparer can be predicted.
b2991d9 to
c0e67b2
Compare
|
@weshaggard @ericstj - is this ok to merge now from the build/versioning prospective? |
|
I dont have a strong opinion on this, just playing devils advocate, should In favour:
Against:
I know this is shipped, but wondering.. |
Implement Enumerable.ToHashSet() Commit migrated from dotnet/corefx@e6b6ba1
Closes #2323
A straight-forward implementation, forgoing any optimisations.
HashSet's constructor already has some for some cases, and others could be wasteful unless not just the number of elements, but the number of elements that are distinct in terms of the equality comparer can be predicted.