Skip to content

[API Proposal]: XxHash128 #77885

Closed
Closed
@xoofx

Description

@xoofx

Background and motivation

Followup of the previous API proposal for XX3 64 bit #75948

The current XxHash3 implementation provides a 64 bit hash. But XXH3 128 is also quite useful for e.g fast content adressable storage scenarios.

This proposal is about adding a XxHash128 API and implementation.

API Proposal

namespace System.IO.Hashing;

public sealed partial class XxHash128 : NonCryptographicHashAlgorithm
{
    public XxHash128();
    public XxHash128(long seed);

    public static byte[] Hash(byte[] source);
    public static byte[] Hash(byte[] source, long seed);
    public static byte[] Hash(ReadOnlySpan<byte> source, long seed = 0);
    public static int Hash(ReadOnlySpan<byte> source, Span<byte> destination, long seed = 0);
    public static bool TryHash(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten, long seed = 0);

    // .NET 7+
    public static UInt128 HashToIntU128(ReadOnlySpan<byte> source, long seed = 0);
    public UInt128 GetCurrentHashAsIntU128();
}

API Usage

int bytesWritten = XxHash128.Hash(source, destination);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions