Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

FarmHashSharp Binding Implementation #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Data.HashFunction.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{D0A9A6
..\appveyor.yml = ..\appveyor.yml
Data.HashFunction.runsettings = Data.HashFunction.runsettings
FriendAssemblies.cs = FriendAssemblies.cs
FriendAssemblies.Unsigned.cs = FriendAssemblies.Unsigned.cs
SolutionInfo.cs = SolutionInfo.cs
EndProjectSection
EndProject
Expand Down Expand Up @@ -57,7 +58,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Data.HashFunction.xx
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Data.HashFunction.HashAlgorithm", "System.Data.HashFunction.HashAlgorithm\System.Data.HashFunction.HashAlgorithm.csproj", "{89C43129-57DC-445C-9521-5C7A6011A878}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Data.HashFunction.FarmHash", "System.Data.HashFunction.FarmHash\System.Data.HashFunction.FarmHash.csproj", "{62D94F50-2DDD-4F81-B4AF-9D1A53C1404C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Data.HashFunction.FarmHash", "System.Data.HashFunction.FarmHash\System.Data.HashFunction.FarmHash.csproj", "{62D94F50-2DDD-4F81-B4AF-9D1A53C1404C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Data.HashFunction.FarmHash.FarmHashSharp", "System.Data.HashFunction.FarmHash.FarmHashSharp\System.Data.HashFunction.FarmHash.FarmHashSharp.csproj", "{49823118-9A33-43FB-A191-7CED19CF79DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Data.HashFunction.Test.Unsigned", "System.Data.HashFunction.Test.Unsigned\System.Data.HashFunction.Test.Unsigned.csproj", "{3B0B798B-AED7-4337-A470-3C7DE50314CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Data.HashFunction.MetroHash", "System.Data.HashFunction.MetroHash\System.Data.HashFunction.MetroHash.csproj", "{F65860E9-DF4C-44F4-9AF0-3E8B2BC682FE}"
EndProject
Expand Down Expand Up @@ -134,6 +139,14 @@ Global
{62D94F50-2DDD-4F81-B4AF-9D1A53C1404C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62D94F50-2DDD-4F81-B4AF-9D1A53C1404C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62D94F50-2DDD-4F81-B4AF-9D1A53C1404C}.Release|Any CPU.Build.0 = Release|Any CPU
{49823118-9A33-43FB-A191-7CED19CF79DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49823118-9A33-43FB-A191-7CED19CF79DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49823118-9A33-43FB-A191-7CED19CF79DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49823118-9A33-43FB-A191-7CED19CF79DF}.Release|Any CPU.Build.0 = Release|Any CPU
{3B0B798B-AED7-4337-A470-3C7DE50314CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B0B798B-AED7-4337-A470-3C7DE50314CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B0B798B-AED7-4337-A470-3C7DE50314CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B0B798B-AED7-4337-A470-3C7DE50314CC}.Release|Any CPU.Build.0 = Release|Any CPU
{F65860E9-DF4C-44F4-9AF0-3E8B2BC682FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F65860E9-DF4C-44F4-9AF0-3E8B2BC682FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F65860E9-DF4C-44F4-9AF0-3E8B2BC682FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
7 changes: 7 additions & 0 deletions src/FriendAssemblies.Unsigned.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.CompilerServices;

#if DEBUG

[assembly:InternalsVisibleTo("System.Data.HashFunction.Test.Unsigned")]

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
/// <summary>
/// Provides instances of implementations of <see cref="IFarmHashSharpHash32"/>.
/// </summary>
public sealed class FarmHashSharpHash32Factory
: FarmHashFingerprint32FactoryBase<IFarmHashSharpHash32>,
IFarmHashSharpHash32Factory
{
/// <summary>
/// Gets the singleton instance of this factory.
/// </summary>
public static IFarmHashSharpHash32Factory Instance { get; } = new FarmHashSharpHash32Factory();


private FarmHashSharpHash32Factory()
{

}


/// <summary>
/// Creates a new <see cref="IFarmHashSharpHash32"/> instance.
/// </summary>
/// <returns>A <see cref="IFarmHashSharpHash32"/> instance.</returns>
public override IFarmHashSharpHash32 Create() =>
new FarmHashSharpHash32_Implementation();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Data.HashFunction.Core;
using System.Data.HashFunction.Core.Utilities.UnifiedData;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
using Farmhash = global::Farmhash.Sharp.Farmhash;

/// <summary>
/// Data.HashFunction implementation of <see cref="IFarmHashSharpHash32"/> via FarmHash.Sharp's Hash32 method.
/// </summary>
internal class FarmHashSharpHash32_Implementation
: HashFunctionAsyncBase,
IFarmHashSharpHash32
{
public override int HashSizeInBits { get; } = 32;


protected override byte[] ComputeHashInternal(IUnifiedData data, CancellationToken cancellationToken)
{
var dataArray = data.ToArray(cancellationToken);

return BitConverter.GetBytes(
Farmhash.Hash32(dataArray, dataArray.Length));
}

protected override async Task<byte[]> ComputeHashAsyncInternal(IUnifiedDataAsync data, CancellationToken cancellationToken)
{
var dataArray = await data.ToArrayAsync(cancellationToken)
.ConfigureAwait(false);

return BitConverter.GetBytes(
Farmhash.Hash32(dataArray, dataArray.Length));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
/// <summary>
/// Provides instances of implementations of <see cref="IFarmHashSharpHash64"/>.
/// </summary>
public sealed class FarmHashSharpHash64Factory
: FarmHashXoHash64FactoryBase<IFarmHashSharpHash64>,
IFarmHashSharpHash64Factory
{
/// <summary>
/// Gets the singleton instance of this factory.
/// </summary>
public static IFarmHashSharpHash64Factory Instance { get; } = new FarmHashSharpHash64Factory();


private FarmHashSharpHash64Factory()
{

}


/// <summary>
/// Creates a new <see cref="IFarmHashSharpHash64"/> instance.
/// </summary>
/// <returns>A <see cref="IFarmHashSharpHash64"/> instance.</returns>
public override IFarmHashSharpHash64 Create() =>
new FarmHashSharpHash64_Implementation();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Data.HashFunction.Core;
using System.Data.HashFunction.Core.Utilities.UnifiedData;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
using Farmhash = global::Farmhash.Sharp.Farmhash;

/// <summary>
/// Data.HashFunction implementation of <see cref="IFarmHashSharpHash64"/> via FarmHash.Sharp's Hash32 method.
/// </summary>
internal class FarmHashSharpHash64_Implementation
: HashFunctionAsyncBase,
IFarmHashSharpHash64
{
public override int HashSizeInBits { get; } = 64;


protected override byte[] ComputeHashInternal(IUnifiedData data, CancellationToken cancellationToken)
{
var dataArray = data.ToArray(cancellationToken);

return BitConverter.GetBytes(
Farmhash.Hash64(dataArray, dataArray.Length));
}

protected override async Task<byte[]> ComputeHashAsyncInternal(IUnifiedDataAsync data, CancellationToken cancellationToken)
{
var dataArray = await data.ToArrayAsync(cancellationToken)
.ConfigureAwait(false);

return BitConverter.GetBytes(
Farmhash.Hash64(dataArray, dataArray.Length));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
/// <summary>
/// Data.HashFunction implementation of <see cref="IFarmHashHash32"/> via FarmHash.Sharp's Hash32 method.
/// </summary>
public interface IFarmHashSharpHash32
: IFarmHashFingerprint32
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
/// <summary>
/// Provides instances of implementations of <see cref="IFarmHashSharpHash32"/>.
/// </summary>
public interface IFarmHashSharpHash32Factory
: IFarmHashFingerprint32Factory
{
/// <summary>
/// Creates a new <see cref="IFarmHashSharpHash32"/> instance.
/// </summary>
/// <returns>A <see cref="IFarmHashSharpHash32"/> instance.</returns>
new IFarmHashSharpHash32 Create();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
/// <summary>
/// Data.HashFunction implementation of <see cref="IFarmHashXoHash64"/> via FarmHash.Sharp's Hash64 method.
/// </summary>
public interface IFarmHashSharpHash64
: IFarmHashXoHash64
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Data.HashFunction.FarmHash.FarmHashSharp
{
/// <summary>
/// Provides instances of implementations of <see cref="IFarmHashSharpHash64"/>.
/// </summary>
public interface IFarmHashSharpHash64Factory
: IFarmHashXoHash64Factory
{
/// <summary>
/// Creates a new <see cref="IFarmHashSharpHash64"/> instance.
/// </summary>
/// <returns>A <see cref="IFarmHashSharpHash64"/> instance.</returns>
new IFarmHashSharpHash64 Create();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Data.HashFunction implementation of FarmHash via FarmHash.Sharp (https://nickbabcock.github.io/Farmhash.Sharp/).</Description>
<Copyright>Copyright 2018</Copyright>
<AssemblyTitle>Data.HashFunction.FarmHash.FarmHashSharp</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<Authors>Data.HashFunction Developers</Authors>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>System.Data.HashFunction.FarmHash.FarmHashSharp</AssemblyName>
<AssemblyOriginatorKeyFile>../Data.HashFunction.Production.snk</AssemblyOriginatorKeyFile>
<SignAssembly>false</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">false</PublicSign>
<PackageId>System.Data.HashFunction.FarmHash.FarmHashSharp</PackageId>
<PackageTags>FarmHash;hash;function;farm;FarmHashSharp;FarmHash.Sharp</PackageTags>
<PackageReleaseNotes>https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes</PackageReleaseNotes>
<PackageLicenseUrl>https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/brandondahler/Data.HashFunction/</RepositoryUrl>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

<PropertyGroup Condition="'$(VcsRevision)'!=''">
<PackageReleaseNotes>$(PackageReleaseNotes)
vcs-revision: $(VcsRevision)
</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\FriendAssemblies.Unsigned.cs" Link="Properties\FriendAssemblies.Unsigned.cs" />
<Compile Include="..\SolutionInfo.cs" Link="Properties\SolutionInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Farmhash.Sharp" Version="0.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\System.Data.HashFunction.Core\System.Data.HashFunction.Core.csproj" />
<ProjectReference Include="..\System.Data.HashFunction.FarmHash\System.Data.HashFunction.FarmHash.csproj" />
<ProjectReference Include="..\System.Data.HashFunction.Interfaces\System.Data.HashFunction.Interfaces.csproj" />
</ItemGroup>

</Project>
Expand Down
6 changes: 6 additions & 0 deletions src/System.Data.HashFunction.Test.Unsigned/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="xunit.methodDisplay" value="method"/>
</appSettings>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Data.HashFunction.FarmHash.FarmHashSharp;
using System.Text;
using Xunit;

namespace System.Data.HashFunction.Test.FarmHash.FarmHashSharp
{
public class FarmHashSharpHash32Factory_Tests
{
[Fact]
public void FarmHashSharpHash32Factory_Instance_IsDefined()
{
Assert.NotNull(FarmHashSharpHash32Factory.Instance);
Assert.IsType<FarmHashSharpHash32Factory>(FarmHashSharpHash32Factory.Instance);
}

[Fact]
public void FarmHashSharpHash32Factory_Create_Works()
{
var farmHashSharpHash32Factory = FarmHashSharpHash32Factory.Instance;
var farmHashSharpHash32 = farmHashSharpHash32Factory.Create();

Assert.NotNull(farmHashSharpHash32);
Assert.IsType<FarmHashSharpHash32_Implementation>(farmHashSharpHash32);
}

}
}
Loading