laget.Fingerprint
1.2.25
Prefix Reserved
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package laget.Fingerprint --version 1.2.25
NuGet\Install-Package laget.Fingerprint -Version 1.2.25
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="laget.Fingerprint" Version="1.2.25" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add laget.Fingerprint --version 1.2.25
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: laget.Fingerprint, 1.2.25"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install laget.Fingerprint as a Cake Addin #addin nuget:?package=laget.Fingerprint&version=1.2.25 // Install laget.Fingerprint as a Cake Tool #tool nuget:?package=laget.Fingerprint&version=1.2.25
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
laget.Fingerprint
Calculates a fingerprint (hash) for an object that can be stored in Memory or a persistent data store.
Configuration
This example is shown using Autofac since this is the go-to IoC for us.
public class FingerprintModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<Fingerprint>().As<IFingerprint>();
builder.Register<IFingerprintManager<Fingerprint, User>>(c =>
new FingerprintManager<Fingerprint, User>(new DictionaryStore<Fingerprint>())
).SingleInstance();
}
}
Usage
Model
Since we do not supply a default implementation of the fingerprint model you need to implement one yourself!
public class Fingerprint : IFingerprint
{
public string Hash { get; set; }
public object Data { get; set; }
public object Metadata { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.Now;
public override bool Equals(object obj)
{
if (!(obj is IFingerprint))
{
return false;
}
if (ReferenceEquals(obj, this))
{
return true;
}
var fingerprint = (IFingerprint)obj;
if (Hash == null)
{
return fingerprint.Hash == null;
}
return Hash.Equals(fingerprint.Hash, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode()
{
return Hash.GetHashCode();
}
public static bool operator ==(Fingerprint lhs, Fingerprint rhs)
{
if (ReferenceEquals(lhs, null))
{
return ReferenceEquals(rhs, null);
}
return lhs.Equals(rhs);
}
public static bool operator !=(Fingerprint lhs, Fingerprint rhs)
{
return !(lhs == rhs);
}
}
Object
This is the object which you like to fingerprint!
public class User : IFingerprintable
{
private readonly Func<User, byte[]> _fingerprintBuilder;
public User()
{
_fingerprintBuilder = FingerprintBuilder<User>
.Create(SHA512.Create().ComputeHash)
.For(x => x.Id)
.For(x => x.Firstname)
.For(x => x.Lastname)
.For(x => x.Email)
.Build();
}
public int Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Email { get; set; }
public DateTime LastActive { get; set; } = DateTime.Now;
public IFingerprint Fingerprint => new Fingerprint
{
Hash = _fingerprintBuilder(this).ToUpperHexString(),
Data = new
{
Id,
Firstname,
Lastname,
Email
},
Metadata = new
{
LastActive
}
};
}
Benchmarks
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
AMD Ryzen Threadripper 3960X, 1 CPU, 12 logical and 12 physical cores
.NET Core SDK=5.0.201
[Host] : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
Job-IQNQYN : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT
Runtime=.NET Core 3.1 IterationCount=50 LaunchCount=2
RunStrategy=Throughput WarmupCount=10
Method | Mean | Error | StdDev | Median | Min | Max |
---|---|---|---|---|---|---|
MD5_Hex | 4.309 us | 0.0170 us | 0.0474 us | 4.298 us | 4.242 us | 4.486 us |
SHA1_Hex | 4.540 us | 0.0153 us | 0.0415 us | 4.544 us | 4.403 us | 4.636 us |
SHA256_Hex | 4.879 us | 0.0171 us | 0.0494 us | 4.876 us | 4.753 us | 5.011 us |
SHA512_Hex | 7.278 us | 0.1210 us | 0.3471 us | 7.142 us | 6.868 us | 8.219 us |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.34 | 68 | 11/4/2024 |
1.2.32 | 110 | 9/3/2024 |
1.2.31 | 117 | 6/3/2024 |
1.2.30 | 268 | 1/20/2024 |
1.2.29 | 271 | 11/23/2023 |
1.2.25 | 171 | 7/3/2023 |
1.2.23 | 237 | 3/10/2023 |
1.2.20 | 277 | 2/26/2023 |
1.2.5 | 2,708 | 8/16/2021 |
1.2.4 | 430 | 8/9/2021 |
1.2.3 | 451 | 6/7/2021 |
1.2.2 | 483 | 5/21/2021 |
1.1.20 | 570 | 4/6/2021 |
1.1.19 | 511 | 3/5/2021 |
1.1.18 | 485 | 2/15/2021 |
1.1.17 | 323 | 2/15/2021 |
1.1.16 | 338 | 2/15/2021 |
1.1.14 | 801 | 2/14/2021 |
1.1.13 | 328 | 2/14/2021 |
1.1.12 | 328 | 2/14/2021 |
1.1.11 | 353 | 2/14/2021 |
1.1.10 | 818 | 2/14/2021 |
1.1.9 | 344 | 2/1/2021 |
1.1.8 | 369 | 1/8/2021 |
1.1.7 | 363 | 12/23/2020 |
1.1.6 | 357 | 12/8/2020 |
1.1.5 | 336 | 12/8/2020 |