Skip to content

Commit

Permalink
Merge branch 'release/1.1.0' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfowler committed Apr 4, 2020
2 parents cfd1bf5 + 05215e5 commit a4efd51
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ TestResult.formatted.xml
*.userprefs
*.orig
*.directory
packages/*/*
*.nupkg
packages/
.vs/
*.DotSettings.user
19 changes: 13 additions & 6 deletions CSF.CollectionComparers.Tests/CSF.CollectionComparers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsTestProject>true</IsTestProject>
<ReleaseVersion>1.0.0</ReleaseVersion>
<NoWarn>1701;1702;NU1603</NoWarn>
<ReleaseVersion>1.1.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.11.0" />
<PackageReference Include="AutoFixture.AutoMoq" Version="4.11.0" />
<PackageReference Include="AutoFixture.NUnit3" Version="4.11.0" />
<PackageReference Include="coverlet.msbuild" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="AutoFixture.NUnit3" Version="4.10.0" />
<PackageReference Include="AutoFixture.AutoMoq" Version="4.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="NunitXml.TestLogger" Version="2.1.41" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CSF.CollectionComparers\CSF.CollectionComparers.csproj" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CSF.CollectionComparers.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Microsoft Visual Studio Solution File, Format Version 11.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSF.CollectionComparers", "CSF.CollectionComparers\CSF.CollectionComparers.csproj", "{A7339D98-0F8B-4EA2-B3E6-9EA4104E51F7}"
EndProject
Expand Down Expand Up @@ -161,6 +161,6 @@ Global
$25.NamingStyle = PascalCase
$25.IncludeInstanceMembers = True
$25.IncludeStaticEntities = True
version = 1.0.0
version = 1.1.0
EndGlobalSection
EndGlobal
28 changes: 27 additions & 1 deletion CSF.CollectionComparers/BagEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,22 @@ public int GetHashCode(IEnumerable<TItem> obj)
if (ReferenceEquals(obj, null))
throw new ArgumentNullException(nameof(obj));

return obj.Aggregate(0, (acc, next) => acc ^ GetItemHashCode(next, itemEqComparer));
var counts = new Dictionary<object, long>();
foreach(object current in obj)
{
var item = current ?? new NullObject();
if (!counts.ContainsKey(item)) counts.Add(item, 0);
counts[item] = counts[item] + 1;
}

return counts.Aggregate(0, (acc, next) =>
{
unchecked
{
var itemHash = next.Key is TItem item ? GetItemHashCode(item, itemEqComparer) : 31;
return acc ^ itemHash ^ next.Value.GetHashCode();
}
});
}

/// <summary>
Expand All @@ -152,5 +167,16 @@ public BagEqualityComparer(IEqualityComparer<TItem> itemEqComparer = null, IComp
this.itemEqComparer = itemEqComparer ?? EqualityComparer<TItem>.Default;
this.itemComparer = itemComparer ?? Comparer<TItem>.Default;
}

/// <summary>
/// This object is used to represent nulls when getting a hash code. This is because an actual null is not permitted
/// as a dictionary key.
/// </summary>
class NullObject
{
public override bool Equals(object obj) => obj is NullObject;

public override int GetHashCode() => 31;
}
}
}
31 changes: 17 additions & 14 deletions CSF.CollectionComparers/CSF.CollectionComparers.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.2</TargetFrameworks>
<PackOnBuild>true</PackOnBuild>
<Authors>CSF Software Ltd</Authors>
<TargetFrameworks>netstandard2.0;netstandard1.2;net45</TargetFrameworks>
<Authors>craigfowler</Authors>

<PackageId>CSF.CollectionComparers</PackageId>
<Title>Collection comparers</Title>
<Description>Implementations of the generic IEqualityComparer&lt;T&gt; which are used for comparing generic IEnumerable&lt;T&gt; objects. These equality comparers represent various comparison strategies such as list/sequence, set and bag equality.

In each case, effort has been made to use the "best" algorithm available for equality-testing.</Description>
<ReleaseVersion>1.0.0</ReleaseVersion>
<ReleaseVersion>1.1.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>Copyright 2020 - CSF Software Limited</Copyright>
<PackageProjectUrl>https://github.com/csf-dev/CSF.CollectionComparers</PackageProjectUrl>
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\CSF-Software-OSS.snk</AssemblyOriginatorKeyFile>
<PackageId>CSF.CollectionComparers</PackageId>
<PackageVersion>1.0.0</PackageVersion>
<Summary>Classes implementing IEqualityComparer&lt;IEnumerable&lt;T&gt;&gt; providing strategies for comparing collections of items/objects.</Summary>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DocumentationFile>bin\Debug\netstandard1.2\CSF.CollectionComparers.xml</DocumentationFile>
<DocumentationFile>bin\Debug\$(TargetFramework)\CSF.CollectionComparers.xml</DocumentationFile>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DocumentationFile>bin\Release\netstandard1.2\CSF.CollectionComparers.xml</DocumentationFile>
<DocumentationFile>bin\Release\$(TargetFramework)\CSF.CollectionComparers.xml</DocumentationFile>
<DebugType></DebugType>
<DefineConstants>TRACE;RELEASE;NETSTANDARD;NETSTANDARD1_2</DefineConstants>
<DocumentationFile>bin\Release\netstandard1.2\CSF.CollectionComparers.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
</ItemGroup>
<Import Project="..\Tools\EnableMultiTargetingWithMono.targets" />
</Project>

0 comments on commit a4efd51

Please sign in to comment.