Skip to content

Commit 0f6a5db

Browse files
committed
Add Crc32
1 parent f2813c7 commit 0f6a5db

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/LibDeflate/Checksums/Crc32.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibDeflate.Checksums
5+
{
6+
using static Imports.Checksums;
7+
8+
public struct Crc32
9+
{
10+
private uint _currentCrc;
11+
12+
public uint Hash => _currentCrc;
13+
14+
public void Append(ReadOnlySpan<byte> input)
15+
=> _currentCrc = AppendCore(_currentCrc, input);
16+
17+
public uint Compute(ReadOnlySpan<byte> input)
18+
=> _currentCrc = AppendCore(0, input);
19+
20+
private static uint AppendCore(uint crc, ReadOnlySpan<byte> input)
21+
=> libdeflate_crc32(crc, MemoryMarshal.GetReference(input), (nuint)input.Length);
22+
}
23+
}

0 commit comments

Comments
 (0)