mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-24 07:54:39 +00:00
ran formatting
This commit is contained in:
@@ -19,22 +19,82 @@ namespace System.Numerics
|
||||
public static unsafe class BitOperations
|
||||
{
|
||||
// hack: should be public because of inline
|
||||
public static readonly byte* TrailingZeroCountDeBruijn = GetArrayPointer(new byte[]
|
||||
{
|
||||
00, 01, 28, 02, 29, 14, 24, 03,
|
||||
30, 22, 20, 15, 25, 17, 04, 08,
|
||||
31, 27, 13, 23, 21, 19, 16, 07,
|
||||
26, 12, 18, 06, 11, 05, 10, 09
|
||||
});
|
||||
public static readonly byte* TrailingZeroCountDeBruijn = GetArrayPointer(
|
||||
new byte[]
|
||||
{
|
||||
00,
|
||||
01,
|
||||
28,
|
||||
02,
|
||||
29,
|
||||
14,
|
||||
24,
|
||||
03,
|
||||
30,
|
||||
22,
|
||||
20,
|
||||
15,
|
||||
25,
|
||||
17,
|
||||
04,
|
||||
08,
|
||||
31,
|
||||
27,
|
||||
13,
|
||||
23,
|
||||
21,
|
||||
19,
|
||||
16,
|
||||
07,
|
||||
26,
|
||||
12,
|
||||
18,
|
||||
06,
|
||||
11,
|
||||
05,
|
||||
10,
|
||||
09,
|
||||
}
|
||||
);
|
||||
|
||||
// hack: should be public because of inline
|
||||
public static readonly byte* Log2DeBruijn = GetArrayPointer(new byte[]
|
||||
{
|
||||
00, 09, 01, 10, 13, 21, 02, 29,
|
||||
11, 14, 16, 18, 22, 25, 03, 30,
|
||||
08, 12, 20, 28, 15, 17, 24, 07,
|
||||
19, 27, 23, 06, 26, 05, 04, 31
|
||||
});
|
||||
public static readonly byte* Log2DeBruijn = GetArrayPointer(
|
||||
new byte[]
|
||||
{
|
||||
00,
|
||||
09,
|
||||
01,
|
||||
10,
|
||||
13,
|
||||
21,
|
||||
02,
|
||||
29,
|
||||
11,
|
||||
14,
|
||||
16,
|
||||
18,
|
||||
22,
|
||||
25,
|
||||
03,
|
||||
30,
|
||||
08,
|
||||
12,
|
||||
20,
|
||||
28,
|
||||
15,
|
||||
17,
|
||||
24,
|
||||
07,
|
||||
19,
|
||||
27,
|
||||
23,
|
||||
06,
|
||||
26,
|
||||
05,
|
||||
04,
|
||||
31,
|
||||
}
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the integer (floor) log of the specified value, base 2.
|
||||
@@ -69,7 +129,8 @@ namespace System.Numerics
|
||||
// uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
|
||||
return Log2DeBruijn[
|
||||
// Using deBruijn sequence, k=2, n=5 (2^5=32) : 0b_0000_0111_1100_0100_1010_1100_1101_1101u
|
||||
(int)((value * 0x07C4ACDDu) >> 27)];
|
||||
(int)((value * 0x07C4ACDDu) >> 27)
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -98,8 +159,7 @@ namespace System.Numerics
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int TrailingZeroCount(int value)
|
||||
=> TrailingZeroCount((uint)value);
|
||||
public static int TrailingZeroCount(int value) => TrailingZeroCount((uint)value);
|
||||
|
||||
/// <summary>
|
||||
/// Count the number of trailing zero bits in an integer value.
|
||||
@@ -118,7 +178,8 @@ namespace System.Numerics
|
||||
// uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
|
||||
return TrailingZeroCountDeBruijn[
|
||||
// Using deBruijn sequence, k=2, n=5 (2^5=32) : 0b_0000_0111_0111_1100_1011_0101_0011_0001u
|
||||
(int)(((value & (uint)-(int)value) * 0x077CB531u) >> 27)]; // Multi-cast mitigates redundant conv.u8
|
||||
(int)(((value & (uint)-(int)value) * 0x077CB531u) >> 27)
|
||||
]; // Multi-cast mitigates redundant conv.u8
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,8 +188,7 @@ namespace System.Numerics
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int TrailingZeroCount(long value)
|
||||
=> TrailingZeroCount((ulong)value);
|
||||
public static int TrailingZeroCount(long value) => TrailingZeroCount((ulong)value);
|
||||
|
||||
/// <summary>
|
||||
/// Count the number of trailing zero bits in a mask.
|
||||
@@ -157,8 +217,8 @@ namespace System.Numerics
|
||||
/// Any value outside the range [0..31] is treated as congruent mod 32.</param>
|
||||
/// <returns>The rotated value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint RotateLeft(uint value, int offset)
|
||||
=> (value << offset) | (value >> (32 - offset));
|
||||
public static uint RotateLeft(uint value, int offset) =>
|
||||
(value << offset) | (value >> (32 - offset));
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified value left by the specified number of bits.
|
||||
@@ -169,8 +229,8 @@ namespace System.Numerics
|
||||
/// Any value outside the range [0..63] is treated as congruent mod 64.</param>
|
||||
/// <returns>The rotated value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong RotateLeft(ulong value, int offset)
|
||||
=> (value << offset) | (value >> (64 - offset));
|
||||
public static ulong RotateLeft(ulong value, int offset) =>
|
||||
(value << offset) | (value >> (64 - offset));
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified value right by the specified number of bits.
|
||||
@@ -181,8 +241,8 @@ namespace System.Numerics
|
||||
/// Any value outside the range [0..31] is treated as congruent mod 32.</param>
|
||||
/// <returns>The rotated value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint RotateRight(uint value, int offset)
|
||||
=> (value >> offset) | (value << (32 - offset));
|
||||
public static uint RotateRight(uint value, int offset) =>
|
||||
(value >> offset) | (value << (32 - offset));
|
||||
|
||||
/// <summary>
|
||||
/// Rotates the specified value right by the specified number of bits.
|
||||
@@ -193,8 +253,8 @@ namespace System.Numerics
|
||||
/// Any value outside the range [0..63] is treated as congruent mod 64.</param>
|
||||
/// <returns>The rotated value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong RotateRight(ulong value, int offset)
|
||||
=> (value >> offset) | (value << (64 - offset));
|
||||
public static ulong RotateRight(ulong value, int offset) =>
|
||||
(value >> offset) | (value << (64 - offset));
|
||||
|
||||
/// <summary>
|
||||
/// Count the number of leading zero bits in a mask.
|
||||
@@ -221,9 +281,11 @@ namespace System.Numerics
|
||||
value |= value >> 16;
|
||||
|
||||
// uint.MaxValue >> 27 is always in range [0 - 31] so we use Unsafe.AddByteOffset to avoid bounds check
|
||||
return 31 ^ Log2DeBruijn[
|
||||
// uint|long -> IntPtr cast on 32-bit platforms does expensive overflow checks not needed here
|
||||
(int)((value * 0x07C4ACDDu) >> 27)];
|
||||
return 31
|
||||
^ Log2DeBruijn[
|
||||
// uint|long -> IntPtr cast on 32-bit platforms does expensive overflow checks not needed here
|
||||
(int)((value * 0x07C4ACDDu) >> 27)
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,14 +16,21 @@ namespace ZstdSharp
|
||||
private Compressor? compressor;
|
||||
private ZSTD_outBuffer_s output;
|
||||
|
||||
public CompressionStream(Stream stream, int level = Compressor.DefaultCompressionLevel,
|
||||
int bufferSize = 0, bool leaveOpen = true)
|
||||
: this(stream, new Compressor(level), bufferSize, false, leaveOpen)
|
||||
{
|
||||
}
|
||||
public CompressionStream(
|
||||
Stream stream,
|
||||
int level = Compressor.DefaultCompressionLevel,
|
||||
int bufferSize = 0,
|
||||
bool leaveOpen = true
|
||||
)
|
||||
: this(stream, new Compressor(level), bufferSize, false, leaveOpen) { }
|
||||
|
||||
public CompressionStream(Stream stream, Compressor compressor, int bufferSize = 0,
|
||||
bool preserveCompressor = true, bool leaveOpen = true)
|
||||
public CompressionStream(
|
||||
Stream stream,
|
||||
Compressor compressor,
|
||||
int bufferSize = 0,
|
||||
bool preserveCompressor = true,
|
||||
bool leaveOpen = true
|
||||
)
|
||||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
@@ -40,9 +47,11 @@ namespace ZstdSharp
|
||||
this.leaveOpen = leaveOpen;
|
||||
|
||||
var outputBufferSize =
|
||||
bufferSize > 0 ? bufferSize : (int) Methods.ZSTD_CStreamOutSize().EnsureZstdSuccess();
|
||||
bufferSize > 0
|
||||
? bufferSize
|
||||
: (int)Methods.ZSTD_CStreamOutSize().EnsureZstdSuccess();
|
||||
outputBuffer = ArrayPool<byte>.Shared.Rent(outputBufferSize);
|
||||
output = new ZSTD_outBuffer_s {pos = 0, size = (nuint) outputBufferSize};
|
||||
output = new ZSTD_outBuffer_s { pos = 0, size = (nuint)outputBufferSize };
|
||||
}
|
||||
|
||||
public void SetParameter(ZSTD_cParameter parameter, int value)
|
||||
@@ -120,97 +129,147 @@ namespace ZstdSharp
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
=> FlushInternal(ZSTD_EndDirective.ZSTD_e_flush);
|
||||
public override void Flush() => FlushInternal(ZSTD_EndDirective.ZSTD_e_flush);
|
||||
|
||||
public override async Task FlushAsync(CancellationToken cancellationToken)
|
||||
=> await FlushInternalAsync(ZSTD_EndDirective.ZSTD_e_flush, cancellationToken).ConfigureAwait(false);
|
||||
public override async Task FlushAsync(CancellationToken cancellationToken) =>
|
||||
await FlushInternalAsync(ZSTD_EndDirective.ZSTD_e_flush, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
private void FlushInternal(ZSTD_EndDirective directive) => WriteInternal(null, directive);
|
||||
|
||||
private async Task FlushInternalAsync(ZSTD_EndDirective directive,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
await WriteInternalAsync(null, directive, cancellationToken).ConfigureAwait(false);
|
||||
private async Task FlushInternalAsync(
|
||||
ZSTD_EndDirective directive,
|
||||
CancellationToken cancellationToken = default
|
||||
) => await WriteInternalAsync(null, directive, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
=> Write(new ReadOnlySpan<byte>(buffer, offset, count));
|
||||
public override void Write(byte[] buffer, int offset, int count) =>
|
||||
Write(new ReadOnlySpan<byte>(buffer, offset, count));
|
||||
|
||||
#if !NETSTANDARD2_0 && !NETFRAMEWORK
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
=> WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue);
|
||||
public override void Write(ReadOnlySpan<byte> buffer) =>
|
||||
WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue);
|
||||
#else
|
||||
public void Write(ReadOnlySpan<byte> buffer)
|
||||
=> WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue);
|
||||
public void Write(ReadOnlySpan<byte> buffer) =>
|
||||
WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue);
|
||||
#endif
|
||||
|
||||
private void WriteInternal(ReadOnlySpan<byte> buffer, ZSTD_EndDirective directive)
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
|
||||
var input = new ZSTD_inBuffer_s {pos = 0, size = buffer != null ? (nuint) buffer.Length : 0};
|
||||
var input = new ZSTD_inBuffer_s
|
||||
{
|
||||
pos = 0,
|
||||
size = buffer != null ? (nuint)buffer.Length : 0,
|
||||
};
|
||||
nuint remaining;
|
||||
do
|
||||
{
|
||||
output.pos = 0;
|
||||
remaining = CompressStream(ref input, buffer, directive);
|
||||
|
||||
var written = (int) output.pos;
|
||||
var written = (int)output.pos;
|
||||
if (written > 0)
|
||||
innerStream.Write(outputBuffer, 0, written);
|
||||
} while (directive == ZSTD_EndDirective.ZSTD_e_continue ? input.pos < input.size : remaining > 0);
|
||||
} while (
|
||||
directive == ZSTD_EndDirective.ZSTD_e_continue
|
||||
? input.pos < input.size
|
||||
: remaining > 0
|
||||
);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD2_0 && !NETFRAMEWORK
|
||||
private async ValueTask WriteInternalAsync(ReadOnlyMemory<byte>? buffer, ZSTD_EndDirective directive,
|
||||
CancellationToken cancellationToken = default)
|
||||
private async ValueTask WriteInternalAsync(
|
||||
ReadOnlyMemory<byte>? buffer,
|
||||
ZSTD_EndDirective directive,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
#else
|
||||
private async Task WriteInternalAsync(ReadOnlyMemory<byte>? buffer, ZSTD_EndDirective directive,
|
||||
CancellationToken cancellationToken = default)
|
||||
private async Task WriteInternalAsync(
|
||||
ReadOnlyMemory<byte>? buffer,
|
||||
ZSTD_EndDirective directive,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
#endif
|
||||
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
|
||||
var input = new ZSTD_inBuffer_s { pos = 0, size = buffer.HasValue ? (nuint)buffer.Value.Length : 0 };
|
||||
var input = new ZSTD_inBuffer_s
|
||||
{
|
||||
pos = 0,
|
||||
size = buffer.HasValue ? (nuint)buffer.Value.Length : 0,
|
||||
};
|
||||
nuint remaining;
|
||||
do
|
||||
{
|
||||
output.pos = 0;
|
||||
remaining = CompressStream(ref input, buffer.HasValue ? buffer.Value.Span : null, directive);
|
||||
remaining = CompressStream(
|
||||
ref input,
|
||||
buffer.HasValue ? buffer.Value.Span : null,
|
||||
directive
|
||||
);
|
||||
|
||||
var written = (int) output.pos;
|
||||
var written = (int)output.pos;
|
||||
if (written > 0)
|
||||
await innerStream.WriteAsync(outputBuffer, 0, written, cancellationToken).ConfigureAwait(false);
|
||||
} while (directive == ZSTD_EndDirective.ZSTD_e_continue ? input.pos < input.size : remaining > 0);
|
||||
await innerStream
|
||||
.WriteAsync(outputBuffer, 0, written, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
} while (
|
||||
directive == ZSTD_EndDirective.ZSTD_e_continue
|
||||
? input.pos < input.size
|
||||
: remaining > 0
|
||||
);
|
||||
}
|
||||
|
||||
#if !NETSTANDARD2_0 && !NETFRAMEWORK
|
||||
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
=> WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken).AsTask();
|
||||
public override Task WriteAsync(
|
||||
byte[] buffer,
|
||||
int offset,
|
||||
int count,
|
||||
CancellationToken cancellationToken
|
||||
) =>
|
||||
WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken).AsTask();
|
||||
|
||||
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer,
|
||||
CancellationToken cancellationToken = default)
|
||||
=> await WriteInternalAsync(buffer, ZSTD_EndDirective.ZSTD_e_continue, cancellationToken).ConfigureAwait(false);
|
||||
public override async ValueTask WriteAsync(
|
||||
ReadOnlyMemory<byte> buffer,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
await WriteInternalAsync(buffer, ZSTD_EndDirective.ZSTD_e_continue, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
#else
|
||||
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
=> WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken);
|
||||
public override Task WriteAsync(
|
||||
byte[] buffer,
|
||||
int offset,
|
||||
int count,
|
||||
CancellationToken cancellationToken
|
||||
) => WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken);
|
||||
|
||||
public async Task WriteAsync(ReadOnlyMemory<byte> buffer,
|
||||
CancellationToken cancellationToken = default)
|
||||
=> await WriteInternalAsync(buffer, ZSTD_EndDirective.ZSTD_e_continue, cancellationToken).ConfigureAwait(false);
|
||||
public async Task WriteAsync(
|
||||
ReadOnlyMemory<byte> buffer,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
await WriteInternalAsync(buffer, ZSTD_EndDirective.ZSTD_e_continue, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
#endif
|
||||
|
||||
internal unsafe nuint CompressStream(ref ZSTD_inBuffer_s input, ReadOnlySpan<byte> inputBuffer,
|
||||
ZSTD_EndDirective directive)
|
||||
internal unsafe nuint CompressStream(
|
||||
ref ZSTD_inBuffer_s input,
|
||||
ReadOnlySpan<byte> inputBuffer,
|
||||
ZSTD_EndDirective directive
|
||||
)
|
||||
{
|
||||
fixed (byte* inputBufferPtr = inputBuffer)
|
||||
fixed (byte* outputBufferPtr = outputBuffer)
|
||||
{
|
||||
input.src = inputBufferPtr;
|
||||
output.dst = outputBufferPtr;
|
||||
return compressor.NotNull().CompressStream(ref input, ref output, directive).EnsureZstdSuccess();
|
||||
return compressor
|
||||
.NotNull()
|
||||
.CompressStream(ref input, ref output, directive)
|
||||
.EnsureZstdSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,9 +285,13 @@ namespace ZstdSharp
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
public override long Seek(long offset, SeekOrigin origin) =>
|
||||
throw new NotSupportedException();
|
||||
|
||||
public override void SetLength(long value) => throw new NotSupportedException();
|
||||
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
throw new NotSupportedException();
|
||||
|
||||
private void EnsureNotDisposed()
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@ namespace ZstdSharp
|
||||
{
|
||||
using var cctx = handle.Acquire();
|
||||
fixed (byte* dictPtr = dict)
|
||||
Methods.ZSTD_CCtx_loadDictionary(cctx, dictPtr, (nuint)dict.Length).EnsureZstdSuccess();
|
||||
Methods
|
||||
.ZSTD_CCtx_loadDictionary(cctx, dictPtr, (nuint)dict.Length)
|
||||
.EnsureZstdSuccess();
|
||||
}
|
||||
|
||||
public Compressor(int level = DefaultCompressionLevel)
|
||||
@@ -71,11 +73,11 @@ namespace ZstdSharp
|
||||
Level = level;
|
||||
}
|
||||
|
||||
public static int GetCompressBound(int length)
|
||||
=> (int)Methods.ZSTD_compressBound((nuint)length);
|
||||
public static int GetCompressBound(int length) =>
|
||||
(int)Methods.ZSTD_compressBound((nuint)length);
|
||||
|
||||
public static ulong GetCompressBoundLong(ulong length)
|
||||
=> Methods.ZSTD_compressBound((nuint)length);
|
||||
public static ulong GetCompressBoundLong(ulong length) =>
|
||||
Methods.ZSTD_compressBound((nuint)length);
|
||||
|
||||
public Span<byte> Wrap(ReadOnlySpan<byte> src)
|
||||
{
|
||||
@@ -84,8 +86,8 @@ namespace ZstdSharp
|
||||
return new Span<byte>(dest, 0, length);
|
||||
}
|
||||
|
||||
public int Wrap(byte[] src, byte[] dest, int offset)
|
||||
=> Wrap(src, new Span<byte>(dest, offset, dest.Length - offset));
|
||||
public int Wrap(byte[] src, byte[] dest, int offset) =>
|
||||
Wrap(src, new Span<byte>(dest, offset, dest.Length - offset));
|
||||
|
||||
public int Wrap(ReadOnlySpan<byte> src, Span<byte> dest)
|
||||
{
|
||||
@@ -93,19 +95,37 @@ namespace ZstdSharp
|
||||
fixed (byte* destPtr = dest)
|
||||
{
|
||||
using var cctx = handle.Acquire();
|
||||
return (int)Methods.ZSTD_compress2(cctx, destPtr, (nuint)dest.Length, srcPtr, (nuint)src.Length)
|
||||
.EnsureZstdSuccess();
|
||||
return (int)
|
||||
Methods
|
||||
.ZSTD_compress2(
|
||||
cctx,
|
||||
destPtr,
|
||||
(nuint)dest.Length,
|
||||
srcPtr,
|
||||
(nuint)src.Length
|
||||
)
|
||||
.EnsureZstdSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
public int Wrap(ArraySegment<byte> src, ArraySegment<byte> dest)
|
||||
=> Wrap((ReadOnlySpan<byte>)src, dest);
|
||||
public int Wrap(ArraySegment<byte> src, ArraySegment<byte> dest) =>
|
||||
Wrap((ReadOnlySpan<byte>)src, dest);
|
||||
|
||||
public int Wrap(byte[] src, int srcOffset, int srcLength, byte[] dst, int dstOffset, int dstLength)
|
||||
=> Wrap(new ReadOnlySpan<byte>(src, srcOffset, srcLength), new Span<byte>(dst, dstOffset, dstLength));
|
||||
public int Wrap(
|
||||
byte[] src,
|
||||
int srcOffset,
|
||||
int srcLength,
|
||||
byte[] dst,
|
||||
int dstOffset,
|
||||
int dstLength
|
||||
) =>
|
||||
Wrap(
|
||||
new ReadOnlySpan<byte>(src, srcOffset, srcLength),
|
||||
new Span<byte>(dst, dstOffset, dstLength)
|
||||
);
|
||||
|
||||
public bool TryWrap(byte[] src, byte[] dest, int offset, out int written)
|
||||
=> TryWrap(src, new Span<byte>(dest, offset, dest.Length - offset), out written);
|
||||
public bool TryWrap(byte[] src, byte[] dest, int offset, out int written) =>
|
||||
TryWrap(src, new Span<byte>(dest, offset, dest.Length - offset), out written);
|
||||
|
||||
public bool TryWrap(ReadOnlySpan<byte> src, Span<byte> dest, out int written)
|
||||
{
|
||||
@@ -115,8 +135,13 @@ namespace ZstdSharp
|
||||
nuint returnValue;
|
||||
using (var cctx = handle.Acquire())
|
||||
{
|
||||
returnValue =
|
||||
Methods.ZSTD_compress2(cctx, destPtr, (nuint)dest.Length, srcPtr, (nuint)src.Length);
|
||||
returnValue = Methods.ZSTD_compress2(
|
||||
cctx,
|
||||
destPtr,
|
||||
(nuint)dest.Length,
|
||||
srcPtr,
|
||||
(nuint)src.Length
|
||||
);
|
||||
}
|
||||
|
||||
if (returnValue == unchecked(0 - (nuint)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall))
|
||||
@@ -131,11 +156,23 @@ namespace ZstdSharp
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryWrap(ArraySegment<byte> src, ArraySegment<byte> dest, out int written)
|
||||
=> TryWrap((ReadOnlySpan<byte>)src, dest, out written);
|
||||
public bool TryWrap(ArraySegment<byte> src, ArraySegment<byte> dest, out int written) =>
|
||||
TryWrap((ReadOnlySpan<byte>)src, dest, out written);
|
||||
|
||||
public bool TryWrap(byte[] src, int srcOffset, int srcLength, byte[] dst, int dstOffset, int dstLength, out int written)
|
||||
=> TryWrap(new ReadOnlySpan<byte>(src, srcOffset, srcLength), new Span<byte>(dst, dstOffset, dstLength), out written);
|
||||
public bool TryWrap(
|
||||
byte[] src,
|
||||
int srcOffset,
|
||||
int srcLength,
|
||||
byte[] dst,
|
||||
int dstOffset,
|
||||
int dstLength,
|
||||
out int written
|
||||
) =>
|
||||
TryWrap(
|
||||
new ReadOnlySpan<byte>(src, srcOffset, srcLength),
|
||||
new Span<byte>(dst, dstOffset, dstLength),
|
||||
out written
|
||||
);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -143,13 +180,19 @@ namespace ZstdSharp
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
internal nuint CompressStream(ref ZSTD_inBuffer_s input, ref ZSTD_outBuffer_s output, ZSTD_EndDirective directive)
|
||||
internal nuint CompressStream(
|
||||
ref ZSTD_inBuffer_s input,
|
||||
ref ZSTD_outBuffer_s output,
|
||||
ZSTD_EndDirective directive
|
||||
)
|
||||
{
|
||||
fixed (ZSTD_inBuffer_s* inputPtr = &input)
|
||||
fixed (ZSTD_outBuffer_s* outputPtr = &output)
|
||||
{
|
||||
using var cctx = handle.Acquire();
|
||||
return Methods.ZSTD_compressStream2(cctx, outputPtr, inputPtr, directive).EnsureZstdSuccess();
|
||||
return Methods
|
||||
.ZSTD_compressStream2(cctx, outputPtr, inputPtr, directive)
|
||||
.EnsureZstdSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace ZstdSharp
|
||||
{
|
||||
internal class Constants
|
||||
{
|
||||
//NOTE: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element#remarks
|
||||
//NOTE: https://github.com/dotnet/runtime/blob/v5.0.0-rtm.20519.4/src/libraries/System.Private.CoreLib/src/System/Array.cs#L27
|
||||
public const ulong MaxByteArrayLength = 0x7FFFFFC7;
|
||||
}
|
||||
internal class Constants
|
||||
{
|
||||
//NOTE: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element#remarks
|
||||
//NOTE: https://github.com/dotnet/runtime/blob/v5.0.0-rtm.20519.4/src/libraries/System.Private.CoreLib/src/System/Array.cs#L27
|
||||
public const ulong MaxByteArrayLength = 0x7FFFFFC7;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,22 @@ namespace ZstdSharp
|
||||
private nuint lastDecompressResult = 0;
|
||||
private bool contextDrained = true;
|
||||
|
||||
public DecompressionStream(Stream stream, int bufferSize = 0, bool checkEndOfStream = true, bool leaveOpen = true)
|
||||
: this(stream, new Decompressor(), bufferSize, checkEndOfStream, false, leaveOpen)
|
||||
{
|
||||
}
|
||||
public DecompressionStream(
|
||||
Stream stream,
|
||||
int bufferSize = 0,
|
||||
bool checkEndOfStream = true,
|
||||
bool leaveOpen = true
|
||||
)
|
||||
: this(stream, new Decompressor(), bufferSize, checkEndOfStream, false, leaveOpen) { }
|
||||
|
||||
public DecompressionStream(Stream stream, Decompressor decompressor, int bufferSize = 0,
|
||||
bool checkEndOfStream = true, bool preserveDecompressor = true, bool leaveOpen = true)
|
||||
public DecompressionStream(
|
||||
Stream stream,
|
||||
Decompressor decompressor,
|
||||
int bufferSize = 0,
|
||||
bool checkEndOfStream = true,
|
||||
bool preserveDecompressor = true,
|
||||
bool leaveOpen = true
|
||||
)
|
||||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
@@ -43,9 +52,14 @@ namespace ZstdSharp
|
||||
this.leaveOpen = leaveOpen;
|
||||
this.checkEndOfStream = checkEndOfStream;
|
||||
|
||||
inputBufferSize = bufferSize > 0 ? bufferSize : (int) Methods.ZSTD_DStreamInSize().EnsureZstdSuccess();
|
||||
inputBufferSize =
|
||||
bufferSize > 0 ? bufferSize : (int)Methods.ZSTD_DStreamInSize().EnsureZstdSuccess();
|
||||
inputBuffer = ArrayPool<byte>.Shared.Rent(inputBufferSize);
|
||||
input = new ZSTD_inBuffer_s {pos = (nuint) inputBufferSize, size = (nuint) inputBufferSize};
|
||||
input = new ZSTD_inBuffer_s
|
||||
{
|
||||
pos = (nuint)inputBufferSize,
|
||||
size = (nuint)inputBufferSize,
|
||||
};
|
||||
}
|
||||
|
||||
public void SetParameter(ZSTD_dParameter parameter, int value)
|
||||
@@ -90,8 +104,8 @@ namespace ZstdSharp
|
||||
}
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
=> Read(new Span<byte>(buffer, offset, count));
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
Read(new Span<byte>(buffer, offset, count));
|
||||
|
||||
#if !NETSTANDARD2_0 && !NETFRAMEWORK
|
||||
public override int Read(Span<byte> buffer)
|
||||
@@ -107,7 +121,7 @@ namespace ZstdSharp
|
||||
return 0;
|
||||
}
|
||||
|
||||
var output = new ZSTD_outBuffer_s {pos = 0, size = (nuint) buffer.Length};
|
||||
var output = new ZSTD_outBuffer_s { pos = 0, size = (nuint)buffer.Length };
|
||||
while (true)
|
||||
{
|
||||
// If there is still input available, or there might be data buffered in the decompressor context, flush that out
|
||||
@@ -125,7 +139,7 @@ namespace ZstdSharp
|
||||
// If we have data to return, return it immediately, so we won't stall on Read
|
||||
if (output.pos > 0)
|
||||
{
|
||||
return (int) output.pos;
|
||||
return (int)output.pos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,24 +155,36 @@ namespace ZstdSharp
|
||||
return 0;
|
||||
}
|
||||
|
||||
input.size = (nuint) bytesRead;
|
||||
input.size = (nuint)bytesRead;
|
||||
input.pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if !NETSTANDARD2_0 && !NETFRAMEWORK
|
||||
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
=> ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
|
||||
public override Task<int> ReadAsync(
|
||||
byte[] buffer,
|
||||
int offset,
|
||||
int count,
|
||||
CancellationToken cancellationToken
|
||||
) => ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
|
||||
|
||||
public override async ValueTask<int> ReadAsync(Memory<byte> buffer,
|
||||
CancellationToken cancellationToken = default)
|
||||
public override async ValueTask<int> ReadAsync(
|
||||
Memory<byte> buffer,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
#else
|
||||
|
||||
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
=> ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken);
|
||||
public async Task<int> ReadAsync(Memory<byte> buffer,
|
||||
CancellationToken cancellationToken = default)
|
||||
public override Task<int> ReadAsync(
|
||||
byte[] buffer,
|
||||
int offset,
|
||||
int count,
|
||||
CancellationToken cancellationToken
|
||||
) => ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken);
|
||||
|
||||
public async Task<int> ReadAsync(
|
||||
Memory<byte> buffer,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
#endif
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
@@ -169,7 +195,7 @@ namespace ZstdSharp
|
||||
return 0;
|
||||
}
|
||||
|
||||
var output = new ZSTD_outBuffer_s { pos = 0, size = (nuint)buffer.Length};
|
||||
var output = new ZSTD_outBuffer_s { pos = 0, size = (nuint)buffer.Length };
|
||||
while (true)
|
||||
{
|
||||
// If there is still input available, or there might be data buffered in the decompressor context, flush that out
|
||||
@@ -193,8 +219,13 @@ namespace ZstdSharp
|
||||
|
||||
// Otherwise, read some more input
|
||||
int bytesRead;
|
||||
if ((bytesRead = await innerStream.ReadAsync(inputBuffer, 0, inputBufferSize, cancellationToken)
|
||||
.ConfigureAwait(false)) == 0)
|
||||
if (
|
||||
(
|
||||
bytesRead = await innerStream
|
||||
.ReadAsync(inputBuffer, 0, inputBufferSize, cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) == 0
|
||||
)
|
||||
{
|
||||
if (checkEndOfStream && lastDecompressResult != 0)
|
||||
{
|
||||
@@ -204,7 +235,7 @@ namespace ZstdSharp
|
||||
return 0;
|
||||
}
|
||||
|
||||
input.size = (nuint) bytesRead;
|
||||
input.size = (nuint)bytesRead;
|
||||
input.pos = 0;
|
||||
}
|
||||
}
|
||||
@@ -234,9 +265,13 @@ namespace ZstdSharp
|
||||
|
||||
public override void Flush() => throw new NotSupportedException();
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
public override long Seek(long offset, SeekOrigin origin) =>
|
||||
throw new NotSupportedException();
|
||||
|
||||
public override void SetLength(long value) => throw new NotSupportedException();
|
||||
public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) =>
|
||||
throw new NotSupportedException();
|
||||
|
||||
private void EnsureNotDisposed()
|
||||
{
|
||||
|
||||
@@ -36,38 +36,46 @@ namespace ZstdSharp
|
||||
{
|
||||
using var dctx = handle.Acquire();
|
||||
fixed (byte* dictPtr = dict)
|
||||
Methods.ZSTD_DCtx_loadDictionary(dctx, dictPtr, (nuint)dict.Length).EnsureZstdSuccess();
|
||||
Methods
|
||||
.ZSTD_DCtx_loadDictionary(dctx, dictPtr, (nuint)dict.Length)
|
||||
.EnsureZstdSuccess();
|
||||
}
|
||||
|
||||
public static ulong GetDecompressedSize(ReadOnlySpan<byte> src)
|
||||
{
|
||||
fixed (byte* srcPtr = src)
|
||||
return Methods.ZSTD_decompressBound(srcPtr, (nuint)src.Length).EnsureContentSizeOk();
|
||||
return Methods
|
||||
.ZSTD_decompressBound(srcPtr, (nuint)src.Length)
|
||||
.EnsureContentSizeOk();
|
||||
}
|
||||
|
||||
public static ulong GetDecompressedSize(ArraySegment<byte> src)
|
||||
=> GetDecompressedSize((ReadOnlySpan<byte>)src);
|
||||
public static ulong GetDecompressedSize(ArraySegment<byte> src) =>
|
||||
GetDecompressedSize((ReadOnlySpan<byte>)src);
|
||||
|
||||
public static ulong GetDecompressedSize(byte[] src, int srcOffset, int srcLength)
|
||||
=> GetDecompressedSize(new ReadOnlySpan<byte>(src, srcOffset, srcLength));
|
||||
public static ulong GetDecompressedSize(byte[] src, int srcOffset, int srcLength) =>
|
||||
GetDecompressedSize(new ReadOnlySpan<byte>(src, srcOffset, srcLength));
|
||||
|
||||
public Span<byte> Unwrap(ReadOnlySpan<byte> src, int maxDecompressedSize = int.MaxValue)
|
||||
{
|
||||
var expectedDstSize = GetDecompressedSize(src);
|
||||
if (expectedDstSize > (ulong)maxDecompressedSize)
|
||||
throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall,
|
||||
$"Decompressed content size {expectedDstSize} is greater than {nameof(maxDecompressedSize)} {maxDecompressedSize}");
|
||||
throw new ZstdException(
|
||||
ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall,
|
||||
$"Decompressed content size {expectedDstSize} is greater than {nameof(maxDecompressedSize)} {maxDecompressedSize}"
|
||||
);
|
||||
if (expectedDstSize > Constants.MaxByteArrayLength)
|
||||
throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall,
|
||||
$"Decompressed content size {expectedDstSize} is greater than max possible byte array size {Constants.MaxByteArrayLength}");
|
||||
throw new ZstdException(
|
||||
ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall,
|
||||
$"Decompressed content size {expectedDstSize} is greater than max possible byte array size {Constants.MaxByteArrayLength}"
|
||||
);
|
||||
|
||||
var dest = new byte[expectedDstSize];
|
||||
var length = Unwrap(src, dest);
|
||||
return new Span<byte>(dest, 0, length);
|
||||
}
|
||||
|
||||
public int Unwrap(byte[] src, byte[] dest, int offset)
|
||||
=> Unwrap(src, new Span<byte>(dest, offset, dest.Length - offset));
|
||||
public int Unwrap(byte[] src, byte[] dest, int offset) =>
|
||||
Unwrap(src, new Span<byte>(dest, offset, dest.Length - offset));
|
||||
|
||||
public int Unwrap(ReadOnlySpan<byte> src, Span<byte> dest)
|
||||
{
|
||||
@@ -75,17 +83,34 @@ namespace ZstdSharp
|
||||
fixed (byte* destPtr = dest)
|
||||
{
|
||||
using var dctx = handle.Acquire();
|
||||
return (int)Methods
|
||||
.ZSTD_decompressDCtx(dctx, destPtr, (nuint)dest.Length, srcPtr, (nuint)src.Length)
|
||||
.EnsureZstdSuccess();
|
||||
return (int)
|
||||
Methods
|
||||
.ZSTD_decompressDCtx(
|
||||
dctx,
|
||||
destPtr,
|
||||
(nuint)dest.Length,
|
||||
srcPtr,
|
||||
(nuint)src.Length
|
||||
)
|
||||
.EnsureZstdSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
public int Unwrap(byte[] src, int srcOffset, int srcLength, byte[] dst, int dstOffset, int dstLength)
|
||||
=> Unwrap(new ReadOnlySpan<byte>(src, srcOffset, srcLength), new Span<byte>(dst, dstOffset, dstLength));
|
||||
public int Unwrap(
|
||||
byte[] src,
|
||||
int srcOffset,
|
||||
int srcLength,
|
||||
byte[] dst,
|
||||
int dstOffset,
|
||||
int dstLength
|
||||
) =>
|
||||
Unwrap(
|
||||
new ReadOnlySpan<byte>(src, srcOffset, srcLength),
|
||||
new Span<byte>(dst, dstOffset, dstLength)
|
||||
);
|
||||
|
||||
public bool TryUnwrap(byte[] src, byte[] dest, int offset, out int written)
|
||||
=> TryUnwrap(src, new Span<byte>(dest, offset, dest.Length - offset), out written);
|
||||
public bool TryUnwrap(byte[] src, byte[] dest, int offset, out int written) =>
|
||||
TryUnwrap(src, new Span<byte>(dest, offset, dest.Length - offset), out written);
|
||||
|
||||
public bool TryUnwrap(ReadOnlySpan<byte> src, Span<byte> dest, out int written)
|
||||
{
|
||||
@@ -95,8 +120,13 @@ namespace ZstdSharp
|
||||
nuint returnValue;
|
||||
using (var dctx = handle.Acquire())
|
||||
{
|
||||
returnValue =
|
||||
Methods.ZSTD_decompressDCtx(dctx, destPtr, (nuint)dest.Length, srcPtr, (nuint)src.Length);
|
||||
returnValue = Methods.ZSTD_decompressDCtx(
|
||||
dctx,
|
||||
destPtr,
|
||||
(nuint)dest.Length,
|
||||
srcPtr,
|
||||
(nuint)src.Length
|
||||
);
|
||||
}
|
||||
|
||||
if (returnValue == unchecked(0 - (nuint)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall))
|
||||
@@ -111,8 +141,20 @@ namespace ZstdSharp
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryUnwrap(byte[] src, int srcOffset, int srcLength, byte[] dst, int dstOffset, int dstLength, out int written)
|
||||
=> TryUnwrap(new ReadOnlySpan<byte>(src, srcOffset, srcLength), new Span<byte>(dst, dstOffset, dstLength), out written);
|
||||
public bool TryUnwrap(
|
||||
byte[] src,
|
||||
int srcOffset,
|
||||
int srcLength,
|
||||
byte[] dst,
|
||||
int dstOffset,
|
||||
int dstLength,
|
||||
out int written
|
||||
) =>
|
||||
TryUnwrap(
|
||||
new ReadOnlySpan<byte>(src, srcOffset, srcLength),
|
||||
new Span<byte>(dst, dstOffset, dstLength),
|
||||
out written
|
||||
);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -57,12 +57,8 @@ namespace ZstdSharp
|
||||
if (queue.TryTake(out var job, -1, cancellationToken))
|
||||
((delegate* managed<void*, void>)job.function)(job.opaque);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (InvalidOperationException) { }
|
||||
catch (OperationCanceledException) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
private static JobThreadPool GetThreadPool(void* ctx) => UnmanagedObject.Unwrap<JobThreadPool>(ctx);
|
||||
private static JobThreadPool GetThreadPool(void* ctx) =>
|
||||
UnmanagedObject.Unwrap<JobThreadPool>(ctx);
|
||||
|
||||
/* ZSTD_createThreadPool() : public access point */
|
||||
public static void* ZSTD_createThreadPool(nuint numThreads)
|
||||
@@ -23,7 +24,11 @@ namespace ZstdSharp.Unsafe
|
||||
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
||||
}
|
||||
|
||||
private static void* POOL_create_advanced(nuint numThreads, nuint queueSize, ZSTD_customMem customMem)
|
||||
private static void* POOL_create_advanced(
|
||||
nuint numThreads,
|
||||
nuint queueSize,
|
||||
ZSTD_customMem customMem
|
||||
)
|
||||
{
|
||||
var jobThreadPool = new JobThreadPool((int)numThreads, (int)queueSize);
|
||||
return UnmanagedObject.Wrap(jobThreadPool);
|
||||
@@ -114,4 +119,4 @@ namespace ZstdSharp.Unsafe
|
||||
return jobThreadPool.TryAdd(function, opaque) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@ namespace ZstdSharp
|
||||
/// Parameterless constructor is hidden. Use the static <c>Create</c> factory
|
||||
/// method to create a new safe handle instance.
|
||||
/// </summary>
|
||||
protected SafeZstdHandle() : base(IntPtr.Zero, true)
|
||||
{
|
||||
}
|
||||
protected SafeZstdHandle()
|
||||
: base(IntPtr.Zero, true) { }
|
||||
|
||||
public sealed override bool IsInvalid => handle == IntPtr.Zero;
|
||||
}
|
||||
@@ -33,9 +32,7 @@ namespace ZstdSharp
|
||||
internal sealed unsafe class SafeCctxHandle : SafeZstdHandle
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private SafeCctxHandle()
|
||||
{
|
||||
}
|
||||
private SafeCctxHandle() { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="SafeCctxHandle"/>.
|
||||
@@ -50,7 +47,10 @@ namespace ZstdSharp
|
||||
{
|
||||
var cctx = Methods.ZSTD_createCCtx();
|
||||
if (cctx == null)
|
||||
throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_GENERIC, "Failed to create cctx");
|
||||
throw new ZstdException(
|
||||
ZSTD_ErrorCode.ZSTD_error_GENERIC,
|
||||
"Failed to create cctx"
|
||||
);
|
||||
safeHandle.SetHandle((IntPtr)cctx);
|
||||
success = true;
|
||||
}
|
||||
@@ -85,9 +85,7 @@ namespace ZstdSharp
|
||||
internal sealed unsafe class SafeDctxHandle : SafeZstdHandle
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private SafeDctxHandle()
|
||||
{
|
||||
}
|
||||
private SafeDctxHandle() { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="SafeDctxHandle"/>.
|
||||
@@ -102,7 +100,10 @@ namespace ZstdSharp
|
||||
{
|
||||
var dctx = Methods.ZSTD_createDCtx();
|
||||
if (dctx == null)
|
||||
throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_GENERIC, "Failed to create dctx");
|
||||
throw new ZstdException(
|
||||
ZSTD_ErrorCode.ZSTD_error_GENERIC,
|
||||
"Failed to create dctx"
|
||||
);
|
||||
safeHandle.SetHandle((IntPtr)dctx);
|
||||
success = true;
|
||||
}
|
||||
@@ -140,7 +141,8 @@ namespace ZstdSharp
|
||||
/// Safe handle holders can be <see cref="Dispose"/>d to decrement the safe handle's
|
||||
/// reference count, and can be implicitly converted to pointers to <see cref="T"/>.
|
||||
/// </remarks>
|
||||
internal unsafe ref struct SafeHandleHolder<T> where T : unmanaged
|
||||
internal unsafe ref struct SafeHandleHolder<T>
|
||||
where T : unmanaged
|
||||
{
|
||||
private readonly SafeHandle _handle;
|
||||
|
||||
|
||||
@@ -26,10 +26,16 @@ namespace ZstdSharp
|
||||
public static ulong EnsureContentSizeOk(this ulong returnValue)
|
||||
{
|
||||
if (returnValue == ZSTD_CONTENTSIZE_UNKNOWN)
|
||||
throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_GENERIC, "Decompressed content size is not specified");
|
||||
throw new ZstdException(
|
||||
ZSTD_ErrorCode.ZSTD_error_GENERIC,
|
||||
"Decompressed content size is not specified"
|
||||
);
|
||||
|
||||
if (returnValue == ZSTD_CONTENTSIZE_ERROR)
|
||||
throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_GENERIC, "Decompressed content size cannot be determined (e.g. invalid magic number, srcSize too small)");
|
||||
throw new ZstdException(
|
||||
ZSTD_ErrorCode.ZSTD_error_GENERIC,
|
||||
"Decompressed content size cannot be determined (e.g. invalid magic number, srcSize too small)"
|
||||
);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
@@ -37,7 +43,7 @@ namespace ZstdSharp
|
||||
private static void ThrowException(nuint returnValue, string message)
|
||||
{
|
||||
var code = 0 - returnValue;
|
||||
throw new ZstdException((ZSTD_ErrorCode) code, message);
|
||||
throw new ZstdException((ZSTD_ErrorCode)code, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,10 @@ namespace ZstdSharp.Unsafe
|
||||
private static void* ZSTD_customMalloc(nuint size, ZSTD_customMem customMem)
|
||||
{
|
||||
if (customMem.customAlloc != null)
|
||||
return ((delegate* managed<void*, nuint, void*>)customMem.customAlloc)(customMem.opaque, size);
|
||||
return ((delegate* managed<void*, nuint, void*>)customMem.customAlloc)(
|
||||
customMem.opaque,
|
||||
size
|
||||
);
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
@@ -21,7 +24,10 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* calloc implemented as malloc+memset;
|
||||
* not as efficient as calloc, but next best guess for custom malloc */
|
||||
void* ptr = ((delegate* managed<void*, nuint, void*>)customMem.customAlloc)(customMem.opaque, size);
|
||||
void* ptr = ((delegate* managed<void*, nuint, void*>)customMem.customAlloc)(
|
||||
customMem.opaque,
|
||||
size
|
||||
);
|
||||
memset(ptr, 0, (uint)size);
|
||||
return ptr;
|
||||
}
|
||||
@@ -35,10 +41,13 @@ namespace ZstdSharp.Unsafe
|
||||
if (ptr != null)
|
||||
{
|
||||
if (customMem.customFree != null)
|
||||
((delegate* managed<void*, void*, void>)customMem.customFree)(customMem.opaque, ptr);
|
||||
((delegate* managed<void*, void*, void>)customMem.customFree)(
|
||||
customMem.opaque,
|
||||
ptr
|
||||
);
|
||||
else
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ namespace ZstdSharp.Unsafe
|
||||
public sbyte* ptr;
|
||||
public sbyte* endPtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,14 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* fully refilled */
|
||||
BIT_DStream_unfinished = 0,
|
||||
|
||||
/* still some bits left in bitstream */
|
||||
BIT_DStream_endOfBuffer = 1,
|
||||
|
||||
/* bitstream entirely consumed, bit-exact */
|
||||
BIT_DStream_completed = 2,
|
||||
|
||||
/* user requested more bits than present in bitstream */
|
||||
BIT_DStream_overflow = 3
|
||||
BIT_DStream_overflow = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ namespace ZstdSharp.Unsafe
|
||||
public sbyte* start;
|
||||
public sbyte* limitPtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
|
||||
namespace ZstdSharp.Unsafe
|
||||
{
|
||||
@@ -41,10 +41,14 @@ namespace ZstdSharp.Unsafe
|
||||
assert(val != 0);
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
return MEM_64bits ? (uint)BitOperations.TrailingZeroCount(val) >> 3 : (uint)BitOperations.TrailingZeroCount((uint)val) >> 3;
|
||||
return MEM_64bits
|
||||
? (uint)BitOperations.TrailingZeroCount(val) >> 3
|
||||
: (uint)BitOperations.TrailingZeroCount((uint)val) >> 3;
|
||||
}
|
||||
|
||||
return MEM_64bits ? (uint)BitOperations.LeadingZeroCount(val) >> 3 : (uint)BitOperations.LeadingZeroCount((uint)val) >> 3;
|
||||
return MEM_64bits
|
||||
? (uint)BitOperations.LeadingZeroCount(val) >> 3
|
||||
: (uint)BitOperations.LeadingZeroCount((uint)val) >> 3;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
#endif
|
||||
@@ -11,45 +11,86 @@ namespace ZstdSharp.Unsafe
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
#if NET7_0_OR_GREATER
|
||||
private static ReadOnlySpan<uint> Span_BIT_mask => new uint[32]
|
||||
{
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
7,
|
||||
0xF,
|
||||
0x1F,
|
||||
0x3F,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0x1FF,
|
||||
0x3FF,
|
||||
0x7FF,
|
||||
0xFFF,
|
||||
0x1FFF,
|
||||
0x3FFF,
|
||||
0x7FFF,
|
||||
0xFFFF,
|
||||
0x1FFFF,
|
||||
0x3FFFF,
|
||||
0x7FFFF,
|
||||
0xFFFFF,
|
||||
0x1FFFFF,
|
||||
0x3FFFFF,
|
||||
0x7FFFFF,
|
||||
0xFFFFFF,
|
||||
0x1FFFFFF,
|
||||
0x3FFFFFF,
|
||||
0x7FFFFFF,
|
||||
0xFFFFFFF,
|
||||
0x1FFFFFFF,
|
||||
0x3FFFFFFF,
|
||||
0x7FFFFFFF
|
||||
};
|
||||
private static uint* BIT_mask => (uint*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref MemoryMarshal.GetReference(Span_BIT_mask));
|
||||
private static ReadOnlySpan<uint> Span_BIT_mask =>
|
||||
new uint[32]
|
||||
{
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
7,
|
||||
0xF,
|
||||
0x1F,
|
||||
0x3F,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0x1FF,
|
||||
0x3FF,
|
||||
0x7FF,
|
||||
0xFFF,
|
||||
0x1FFF,
|
||||
0x3FFF,
|
||||
0x7FFF,
|
||||
0xFFFF,
|
||||
0x1FFFF,
|
||||
0x3FFFF,
|
||||
0x7FFFF,
|
||||
0xFFFFF,
|
||||
0x1FFFFF,
|
||||
0x3FFFFF,
|
||||
0x7FFFFF,
|
||||
0xFFFFFF,
|
||||
0x1FFFFFF,
|
||||
0x3FFFFFF,
|
||||
0x7FFFFFF,
|
||||
0xFFFFFFF,
|
||||
0x1FFFFFFF,
|
||||
0x3FFFFFFF,
|
||||
0x7FFFFFFF,
|
||||
};
|
||||
private static uint* BIT_mask =>
|
||||
(uint*)
|
||||
System.Runtime.CompilerServices.Unsafe.AsPointer(
|
||||
ref MemoryMarshal.GetReference(Span_BIT_mask)
|
||||
);
|
||||
#else
|
||||
|
||||
private static readonly uint* BIT_mask = GetArrayPointer(new uint[32] { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF });
|
||||
private static readonly uint* BIT_mask = GetArrayPointer(
|
||||
new uint[32]
|
||||
{
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
7,
|
||||
0xF,
|
||||
0x1F,
|
||||
0x3F,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0x1FF,
|
||||
0x3FF,
|
||||
0x7FF,
|
||||
0xFFF,
|
||||
0x1FFF,
|
||||
0x3FFF,
|
||||
0x7FFF,
|
||||
0xFFFF,
|
||||
0x1FFFF,
|
||||
0x3FFFF,
|
||||
0x7FFFF,
|
||||
0xFFFFF,
|
||||
0x1FFFFF,
|
||||
0x3FFFFF,
|
||||
0x7FFFFF,
|
||||
0xFFFFFF,
|
||||
0x1FFFFFF,
|
||||
0x3FFFFFF,
|
||||
0x7FFFFFF,
|
||||
0xFFFFFFF,
|
||||
0x1FFFFFFF,
|
||||
0x3FFFFFFF,
|
||||
0x7FFFFFFF,
|
||||
}
|
||||
);
|
||||
#endif
|
||||
/*-**************************************************************
|
||||
* bitStream encoding
|
||||
@@ -59,7 +100,11 @@ namespace ZstdSharp.Unsafe
|
||||
* @return : 0 if success,
|
||||
* otherwise an error code (can be tested using ERR_isError()) */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_initCStream(ref BIT_CStream_t bitC, void* startPtr, nuint dstCapacity)
|
||||
private static nuint BIT_initCStream(
|
||||
ref BIT_CStream_t bitC,
|
||||
void* startPtr,
|
||||
nuint dstCapacity
|
||||
)
|
||||
{
|
||||
bitC.bitContainer = 0;
|
||||
bitC.bitPos = 0;
|
||||
@@ -94,7 +139,12 @@ namespace ZstdSharp.Unsafe
|
||||
* can add up to 31 bits into `bitC`.
|
||||
* Note : does not check for register overflow ! */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void BIT_addBits(ref nuint bitC_bitContainer, ref uint bitC_bitPos, nuint value, uint nbBits)
|
||||
private static void BIT_addBits(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
nuint value,
|
||||
uint nbBits
|
||||
)
|
||||
{
|
||||
assert(nbBits < sizeof(uint) * 32 / sizeof(uint));
|
||||
assert(nbBits + bitC_bitPos < (uint)(sizeof(nuint) * 8));
|
||||
@@ -106,7 +156,12 @@ namespace ZstdSharp.Unsafe
|
||||
* works only if `value` is _clean_,
|
||||
* meaning all high bits above nbBits are 0 */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void BIT_addBitsFast(ref nuint bitC_bitContainer, ref uint bitC_bitPos, nuint value, uint nbBits)
|
||||
private static void BIT_addBitsFast(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
nuint value,
|
||||
uint nbBits
|
||||
)
|
||||
{
|
||||
assert(value >> (int)nbBits == 0);
|
||||
assert(nbBits + bitC_bitPos < (uint)(sizeof(nuint) * 8));
|
||||
@@ -118,7 +173,12 @@ namespace ZstdSharp.Unsafe
|
||||
* assumption : bitContainer has not overflowed
|
||||
* unsafe version; does not check buffer overflow */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void BIT_flushBitsFast(ref nuint bitC_bitContainer, ref uint bitC_bitPos, ref sbyte* bitC_ptr, sbyte* bitC_endPtr)
|
||||
private static void BIT_flushBitsFast(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
ref sbyte* bitC_ptr,
|
||||
sbyte* bitC_endPtr
|
||||
)
|
||||
{
|
||||
nuint nbBytes = bitC_bitPos >> 3;
|
||||
assert(bitC_bitPos < (uint)(sizeof(nuint) * 8));
|
||||
@@ -135,7 +195,12 @@ namespace ZstdSharp.Unsafe
|
||||
* note : does not signal buffer overflow.
|
||||
* overflow will be revealed later on using BIT_closeCStream() */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void BIT_flushBits(ref nuint bitC_bitContainer, ref uint bitC_bitPos, ref sbyte* bitC_ptr, sbyte* bitC_endPtr)
|
||||
private static void BIT_flushBits(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
ref sbyte* bitC_ptr,
|
||||
sbyte* bitC_endPtr
|
||||
)
|
||||
{
|
||||
nuint nbBytes = bitC_bitPos >> 3;
|
||||
assert(bitC_bitPos < (uint)(sizeof(nuint) * 8));
|
||||
@@ -152,7 +217,13 @@ namespace ZstdSharp.Unsafe
|
||||
* @return : size of CStream, in bytes,
|
||||
* or 0 if it could not fit into dstBuffer */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_closeCStream(ref nuint bitC_bitContainer, ref uint bitC_bitPos, sbyte* bitC_ptr, sbyte* bitC_endPtr, sbyte* bitC_startPtr)
|
||||
private static nuint BIT_closeCStream(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
sbyte* bitC_ptr,
|
||||
sbyte* bitC_endPtr,
|
||||
sbyte* bitC_startPtr
|
||||
)
|
||||
{
|
||||
BIT_addBitsFast(ref bitC_bitContainer, ref bitC_bitPos, 1, 1);
|
||||
BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
@@ -199,13 +270,16 @@ namespace ZstdSharp.Unsafe
|
||||
switch (srcSize)
|
||||
{
|
||||
case 7:
|
||||
bitD->bitContainer += (nuint)((byte*)srcBuffer)[6] << sizeof(nuint) * 8 - 16;
|
||||
bitD->bitContainer +=
|
||||
(nuint)((byte*)srcBuffer)[6] << sizeof(nuint) * 8 - 16;
|
||||
goto case 6;
|
||||
case 6:
|
||||
bitD->bitContainer += (nuint)((byte*)srcBuffer)[5] << sizeof(nuint) * 8 - 24;
|
||||
bitD->bitContainer +=
|
||||
(nuint)((byte*)srcBuffer)[5] << sizeof(nuint) * 8 - 24;
|
||||
goto case 5;
|
||||
case 5:
|
||||
bitD->bitContainer += (nuint)((byte*)srcBuffer)[4] << sizeof(nuint) * 8 - 32;
|
||||
bitD->bitContainer +=
|
||||
(nuint)((byte*)srcBuffer)[4] << sizeof(nuint) * 8 - 32;
|
||||
goto case 4;
|
||||
case 4:
|
||||
bitD->bitContainer += (nuint)((byte*)srcBuffer)[3] << 24;
|
||||
@@ -224,7 +298,9 @@ namespace ZstdSharp.Unsafe
|
||||
byte lastByte = ((byte*)srcBuffer)[srcSize - 1];
|
||||
bitD->bitsConsumed = lastByte != 0 ? 8 - ZSTD_highbit32(lastByte) : 0;
|
||||
if (lastByte == 0)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)
|
||||
);
|
||||
}
|
||||
|
||||
bitD->bitsConsumed += (uint)((nuint)sizeof(nuint) - srcSize) * 8;
|
||||
@@ -268,7 +344,11 @@ namespace ZstdSharp.Unsafe
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_lookBits(BIT_DStream_t* bitD, uint nbBits)
|
||||
{
|
||||
return BIT_getMiddleBits(bitD->bitContainer, (uint)(sizeof(nuint) * 8) - bitD->bitsConsumed - nbBits, nbBits);
|
||||
return BIT_getMiddleBits(
|
||||
bitD->bitContainer,
|
||||
(uint)(sizeof(nuint) * 8) - bitD->bitsConsumed - nbBits,
|
||||
nbBits
|
||||
);
|
||||
}
|
||||
|
||||
/*! BIT_lookBitsFast() :
|
||||
@@ -278,7 +358,9 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
uint regMask = (uint)(sizeof(nuint) * 8 - 1);
|
||||
assert(nbBits >= 1);
|
||||
return bitD->bitContainer << (int)(bitD->bitsConsumed & regMask) >> (int)(regMask + 1 - nbBits & regMask);
|
||||
return bitD->bitContainer
|
||||
<< (int)(bitD->bitsConsumed & regMask)
|
||||
>> (int)(regMask + 1 - nbBits & regMask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -341,21 +423,18 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
private static ReadOnlySpan<byte> Span_static_zeroFilled => new byte[]
|
||||
{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
private static nuint* static_zeroFilled => (nuint*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref MemoryMarshal.GetReference(Span_static_zeroFilled));
|
||||
private static ReadOnlySpan<byte> Span_static_zeroFilled =>
|
||||
new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
private static nuint* static_zeroFilled =>
|
||||
(nuint*)
|
||||
System.Runtime.CompilerServices.Unsafe.AsPointer(
|
||||
ref MemoryMarshal.GetReference(Span_static_zeroFilled)
|
||||
);
|
||||
#else
|
||||
|
||||
private static readonly nuint* static_zeroFilled = (nuint*)GetArrayPointer(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
|
||||
private static readonly nuint* static_zeroFilled = (nuint*)GetArrayPointer(
|
||||
new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }
|
||||
);
|
||||
#endif
|
||||
/*! BIT_reloadDStream() :
|
||||
* Refill `bitD` from buffer previously set in BIT_initDStream() .
|
||||
@@ -406,7 +485,10 @@ namespace ZstdSharp.Unsafe
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static uint BIT_endOfDStream(BIT_DStream_t* DStream)
|
||||
{
|
||||
return DStream->ptr == DStream->start && DStream->bitsConsumed == (uint)(sizeof(nuint) * 8) ? 1U : 0U;
|
||||
return
|
||||
DStream->ptr == DStream->start && DStream->bitsConsumed == (uint)(sizeof(nuint) * 8)
|
||||
? 1U
|
||||
: 0U;
|
||||
}
|
||||
|
||||
/*-********************************************************
|
||||
@@ -472,7 +554,9 @@ namespace ZstdSharp.Unsafe
|
||||
byte lastByte = ((byte*)srcBuffer)[srcSize - 1];
|
||||
bitD.bitsConsumed = lastByte != 0 ? 8 - ZSTD_highbit32(lastByte) : 0;
|
||||
if (lastByte == 0)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)
|
||||
);
|
||||
}
|
||||
|
||||
bitD.bitsConsumed += (uint)((nuint)sizeof(nuint) - srcSize) * 8;
|
||||
@@ -488,19 +572,33 @@ namespace ZstdSharp.Unsafe
|
||||
* On 64-bits, maxNbBits==56.
|
||||
* @return : value extracted */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_lookBits(nuint bitD_bitContainer, uint bitD_bitsConsumed, uint nbBits)
|
||||
private static nuint BIT_lookBits(
|
||||
nuint bitD_bitContainer,
|
||||
uint bitD_bitsConsumed,
|
||||
uint nbBits
|
||||
)
|
||||
{
|
||||
return BIT_getMiddleBits(bitD_bitContainer, (uint)(sizeof(nuint) * 8) - bitD_bitsConsumed - nbBits, nbBits);
|
||||
return BIT_getMiddleBits(
|
||||
bitD_bitContainer,
|
||||
(uint)(sizeof(nuint) * 8) - bitD_bitsConsumed - nbBits,
|
||||
nbBits
|
||||
);
|
||||
}
|
||||
|
||||
/*! BIT_lookBitsFast() :
|
||||
* unsafe version; only works if nbBits >= 1 */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_lookBitsFast(nuint bitD_bitContainer, uint bitD_bitsConsumed, uint nbBits)
|
||||
private static nuint BIT_lookBitsFast(
|
||||
nuint bitD_bitContainer,
|
||||
uint bitD_bitsConsumed,
|
||||
uint nbBits
|
||||
)
|
||||
{
|
||||
uint regMask = (uint)(sizeof(nuint) * 8 - 1);
|
||||
assert(nbBits >= 1);
|
||||
return bitD_bitContainer << (int)(bitD_bitsConsumed & regMask) >> (int)(regMask + 1 - nbBits & regMask);
|
||||
return bitD_bitContainer
|
||||
<< (int)(bitD_bitsConsumed & regMask)
|
||||
>> (int)(regMask + 1 - nbBits & regMask);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -514,7 +612,11 @@ namespace ZstdSharp.Unsafe
|
||||
* Pay attention to not read more than nbBits contained into local register.
|
||||
* @return : extracted value. */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_readBits(nuint bitD_bitContainer, ref uint bitD_bitsConsumed, uint nbBits)
|
||||
private static nuint BIT_readBits(
|
||||
nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed,
|
||||
uint nbBits
|
||||
)
|
||||
{
|
||||
nuint value = BIT_lookBits(bitD_bitContainer, bitD_bitsConsumed, nbBits);
|
||||
BIT_skipBits(ref bitD_bitsConsumed, nbBits);
|
||||
@@ -524,7 +626,11 @@ namespace ZstdSharp.Unsafe
|
||||
/*! BIT_readBitsFast() :
|
||||
* unsafe version; only works if nbBits >= 1 */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint BIT_readBitsFast(nuint bitD_bitContainer, ref uint bitD_bitsConsumed, uint nbBits)
|
||||
private static nuint BIT_readBitsFast(
|
||||
nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed,
|
||||
uint nbBits
|
||||
)
|
||||
{
|
||||
nuint value = BIT_lookBitsFast(bitD_bitContainer, bitD_bitsConsumed, nbBits);
|
||||
assert(nbBits >= 1);
|
||||
@@ -539,11 +645,22 @@ namespace ZstdSharp.Unsafe
|
||||
* point you must use BIT_reloadDStream() to reload.
|
||||
*/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static BIT_DStream_status BIT_reloadDStreamFast(ref nuint bitD_bitContainer, ref uint bitD_bitsConsumed, ref sbyte* bitD_ptr, sbyte* bitD_start, sbyte* bitD_limitPtr)
|
||||
private static BIT_DStream_status BIT_reloadDStreamFast(
|
||||
ref nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed,
|
||||
ref sbyte* bitD_ptr,
|
||||
sbyte* bitD_start,
|
||||
sbyte* bitD_limitPtr
|
||||
)
|
||||
{
|
||||
if (bitD_ptr < bitD_limitPtr)
|
||||
return BIT_DStream_status.BIT_DStream_overflow;
|
||||
return BIT_reloadDStream_internal(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start);
|
||||
return BIT_reloadDStream_internal(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start
|
||||
);
|
||||
}
|
||||
|
||||
/*! BIT_reloadDStream() :
|
||||
@@ -552,7 +669,13 @@ namespace ZstdSharp.Unsafe
|
||||
* @return : status of `BIT_DStream_t` internal register.
|
||||
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static BIT_DStream_status BIT_reloadDStream(ref nuint bitD_bitContainer, ref uint bitD_bitsConsumed, ref sbyte* bitD_ptr, sbyte* bitD_start, sbyte* bitD_limitPtr)
|
||||
private static BIT_DStream_status BIT_reloadDStream(
|
||||
ref nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed,
|
||||
ref sbyte* bitD_ptr,
|
||||
sbyte* bitD_start,
|
||||
sbyte* bitD_limitPtr
|
||||
)
|
||||
{
|
||||
if (bitD_bitsConsumed > (uint)(sizeof(nuint) * 8))
|
||||
{
|
||||
@@ -563,7 +686,12 @@ namespace ZstdSharp.Unsafe
|
||||
assert(bitD_ptr >= bitD_start);
|
||||
if (bitD_ptr >= bitD_limitPtr)
|
||||
{
|
||||
return BIT_reloadDStream_internal(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start);
|
||||
return BIT_reloadDStream_internal(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start
|
||||
);
|
||||
}
|
||||
|
||||
if (bitD_ptr == bitD_start)
|
||||
@@ -595,7 +723,12 @@ namespace ZstdSharp.Unsafe
|
||||
* 2. look window is valid after shifted down : bitD->ptr >= bitD->start
|
||||
*/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static BIT_DStream_status BIT_reloadDStream_internal(ref nuint bitD_bitContainer, ref uint bitD_bitsConsumed, ref sbyte* bitD_ptr, sbyte* bitD_start)
|
||||
private static BIT_DStream_status BIT_reloadDStream_internal(
|
||||
ref nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed,
|
||||
ref sbyte* bitD_ptr,
|
||||
sbyte* bitD_start
|
||||
)
|
||||
{
|
||||
assert(bitD_bitsConsumed <= (uint)(sizeof(nuint) * 8));
|
||||
bitD_ptr -= bitD_bitsConsumed >> 3;
|
||||
@@ -609,9 +742,15 @@ namespace ZstdSharp.Unsafe
|
||||
* @return : 1 if DStream has _exactly_ reached its end (all bits consumed).
|
||||
*/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static uint BIT_endOfDStream(uint DStream_bitsConsumed, sbyte* DStream_ptr, sbyte* DStream_start)
|
||||
private static uint BIT_endOfDStream(
|
||||
uint DStream_bitsConsumed,
|
||||
sbyte* DStream_ptr,
|
||||
sbyte* DStream_start
|
||||
)
|
||||
{
|
||||
return DStream_ptr == DStream_start && DStream_bitsConsumed == (uint)(sizeof(nuint) * 8) ? 1U : 0U;
|
||||
return DStream_ptr == DStream_start && DStream_bitsConsumed == (uint)(sizeof(nuint) * 8)
|
||||
? 1U
|
||||
: 0U;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint blockSize;
|
||||
public nuint litSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ namespace ZstdSharp.Unsafe
|
||||
public ZDICT_cover_params_t parameters;
|
||||
public nuint compressedSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint* dmerAt;
|
||||
public uint d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint dictSize;
|
||||
public nuint totalCompressedSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint num;
|
||||
public uint size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint key;
|
||||
public uint value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint size;
|
||||
public uint sizeMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint end;
|
||||
public uint score;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint dictBufferCapacity;
|
||||
public ZDICT_cover_params_t parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,112 +2,849 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
private static readonly ZSTD_compressionParameters[][] ZSTD_defaultCParameters = new ZSTD_compressionParameters[4][]
|
||||
{
|
||||
new ZSTD_compressionParameters[23]
|
||||
private static readonly ZSTD_compressionParameters[][] ZSTD_defaultCParameters =
|
||||
new ZSTD_compressionParameters[4][]
|
||||
{
|
||||
new ZSTD_compressionParameters(windowLog: 19, chainLog: 12, hashLog: 13, searchLog: 1, minMatch: 6, targetLength: 1, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 19, chainLog: 13, hashLog: 14, searchLog: 1, minMatch: 7, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 20, chainLog: 15, hashLog: 16, searchLog: 1, minMatch: 6, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 21, chainLog: 16, hashLog: 17, searchLog: 1, minMatch: 5, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 21, chainLog: 18, hashLog: 18, searchLog: 1, minMatch: 5, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 21, chainLog: 18, hashLog: 19, searchLog: 3, minMatch: 5, targetLength: 2, strategy: ZSTD_strategy.ZSTD_greedy),
|
||||
new ZSTD_compressionParameters(windowLog: 21, chainLog: 18, hashLog: 19, searchLog: 3, minMatch: 5, targetLength: 4, strategy: ZSTD_strategy.ZSTD_lazy),
|
||||
new ZSTD_compressionParameters(windowLog: 21, chainLog: 19, hashLog: 20, searchLog: 4, minMatch: 5, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy),
|
||||
new ZSTD_compressionParameters(windowLog: 21, chainLog: 19, hashLog: 20, searchLog: 4, minMatch: 5, targetLength: 16, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 20, hashLog: 21, searchLog: 4, minMatch: 5, targetLength: 16, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 21, hashLog: 22, searchLog: 5, minMatch: 5, targetLength: 16, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 21, hashLog: 22, searchLog: 6, minMatch: 5, targetLength: 16, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 22, hashLog: 23, searchLog: 6, minMatch: 5, targetLength: 32, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 22, hashLog: 22, searchLog: 4, minMatch: 5, targetLength: 32, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 22, hashLog: 23, searchLog: 5, minMatch: 5, targetLength: 32, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 23, hashLog: 23, searchLog: 6, minMatch: 5, targetLength: 32, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 22, chainLog: 22, hashLog: 22, searchLog: 5, minMatch: 5, targetLength: 48, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 23, chainLog: 23, hashLog: 22, searchLog: 5, minMatch: 4, targetLength: 64, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 23, chainLog: 23, hashLog: 22, searchLog: 6, minMatch: 3, targetLength: 64, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 23, chainLog: 24, hashLog: 22, searchLog: 7, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 25, chainLog: 25, hashLog: 23, searchLog: 7, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 26, chainLog: 26, hashLog: 24, searchLog: 7, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 27, chainLog: 27, hashLog: 25, searchLog: 9, minMatch: 3, targetLength: 999, strategy: ZSTD_strategy.ZSTD_btultra2)
|
||||
},
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 12, hashLog: 13, searchLog: 1, minMatch: 5, targetLength: 1, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 13, hashLog: 14, searchLog: 1, minMatch: 6, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 14, hashLog: 14, searchLog: 1, minMatch: 5, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 16, hashLog: 16, searchLog: 1, minMatch: 4, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 16, hashLog: 17, searchLog: 3, minMatch: 5, targetLength: 2, strategy: ZSTD_strategy.ZSTD_greedy),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 17, hashLog: 18, searchLog: 5, minMatch: 5, targetLength: 2, strategy: ZSTD_strategy.ZSTD_greedy),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 3, minMatch: 5, targetLength: 4, strategy: ZSTD_strategy.ZSTD_lazy),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 4, minMatch: 4, targetLength: 4, strategy: ZSTD_strategy.ZSTD_lazy),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 4, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 5, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 6, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 5, minMatch: 4, targetLength: 12, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 7, minMatch: 4, targetLength: 12, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 4, minMatch: 4, targetLength: 16, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 4, minMatch: 3, targetLength: 32, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 18, hashLog: 19, searchLog: 6, minMatch: 3, targetLength: 128, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 6, minMatch: 3, targetLength: 128, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 8, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 6, minMatch: 3, targetLength: 128, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 8, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 10, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 12, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 18, chainLog: 19, hashLog: 19, searchLog: 13, minMatch: 3, targetLength: 999, strategy: ZSTD_strategy.ZSTD_btultra2)
|
||||
},
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 12, hashLog: 12, searchLog: 1, minMatch: 5, targetLength: 1, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 12, hashLog: 13, searchLog: 1, minMatch: 6, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 13, hashLog: 15, searchLog: 1, minMatch: 5, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 15, hashLog: 16, searchLog: 2, minMatch: 5, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 17, hashLog: 17, searchLog: 2, minMatch: 4, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 16, hashLog: 17, searchLog: 3, minMatch: 4, targetLength: 2, strategy: ZSTD_strategy.ZSTD_greedy),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 16, hashLog: 17, searchLog: 3, minMatch: 4, targetLength: 4, strategy: ZSTD_strategy.ZSTD_lazy),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 16, hashLog: 17, searchLog: 3, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 16, hashLog: 17, searchLog: 4, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 16, hashLog: 17, searchLog: 5, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 16, hashLog: 17, searchLog: 6, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 17, hashLog: 17, searchLog: 5, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 7, minMatch: 4, targetLength: 12, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 3, minMatch: 4, targetLength: 12, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 4, minMatch: 3, targetLength: 32, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 6, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 6, minMatch: 3, targetLength: 128, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 8, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 10, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 5, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 7, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 9, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 17, chainLog: 18, hashLog: 17, searchLog: 11, minMatch: 3, targetLength: 999, strategy: ZSTD_strategy.ZSTD_btultra2)
|
||||
},
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 12, hashLog: 13, searchLog: 1, minMatch: 5, targetLength: 1, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 15, searchLog: 1, minMatch: 5, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 15, searchLog: 1, minMatch: 4, targetLength: 0, strategy: ZSTD_strategy.ZSTD_fast),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 15, searchLog: 2, minMatch: 4, targetLength: 0, strategy: ZSTD_strategy.ZSTD_dfast),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 14, searchLog: 4, minMatch: 4, targetLength: 2, strategy: ZSTD_strategy.ZSTD_greedy),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 14, searchLog: 3, minMatch: 4, targetLength: 4, strategy: ZSTD_strategy.ZSTD_lazy),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 14, searchLog: 4, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 14, searchLog: 6, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 14, hashLog: 14, searchLog: 8, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_lazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 14, searchLog: 5, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 14, searchLog: 9, minMatch: 4, targetLength: 8, strategy: ZSTD_strategy.ZSTD_btlazy2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 14, searchLog: 3, minMatch: 4, targetLength: 12, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 14, searchLog: 4, minMatch: 3, targetLength: 24, strategy: ZSTD_strategy.ZSTD_btopt),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 14, searchLog: 5, minMatch: 3, targetLength: 32, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 6, minMatch: 3, targetLength: 64, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 7, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 5, minMatch: 3, targetLength: 48, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 6, minMatch: 3, targetLength: 128, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 7, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 8, minMatch: 3, targetLength: 256, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 8, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 9, minMatch: 3, targetLength: 512, strategy: ZSTD_strategy.ZSTD_btultra2),
|
||||
new ZSTD_compressionParameters(windowLog: 14, chainLog: 15, hashLog: 15, searchLog: 10, minMatch: 3, targetLength: 999, strategy: ZSTD_strategy.ZSTD_btultra2)
|
||||
}
|
||||
};
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 19,
|
||||
chainLog: 12,
|
||||
hashLog: 13,
|
||||
searchLog: 1,
|
||||
minMatch: 6,
|
||||
targetLength: 1,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 19,
|
||||
chainLog: 13,
|
||||
hashLog: 14,
|
||||
searchLog: 1,
|
||||
minMatch: 7,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 20,
|
||||
chainLog: 15,
|
||||
hashLog: 16,
|
||||
searchLog: 1,
|
||||
minMatch: 6,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 21,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 21,
|
||||
chainLog: 18,
|
||||
hashLog: 18,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 21,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 3,
|
||||
minMatch: 5,
|
||||
targetLength: 2,
|
||||
strategy: ZSTD_strategy.ZSTD_greedy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 21,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 3,
|
||||
minMatch: 5,
|
||||
targetLength: 4,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 21,
|
||||
chainLog: 19,
|
||||
hashLog: 20,
|
||||
searchLog: 4,
|
||||
minMatch: 5,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 21,
|
||||
chainLog: 19,
|
||||
hashLog: 20,
|
||||
searchLog: 4,
|
||||
minMatch: 5,
|
||||
targetLength: 16,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 20,
|
||||
hashLog: 21,
|
||||
searchLog: 4,
|
||||
minMatch: 5,
|
||||
targetLength: 16,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 21,
|
||||
hashLog: 22,
|
||||
searchLog: 5,
|
||||
minMatch: 5,
|
||||
targetLength: 16,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 21,
|
||||
hashLog: 22,
|
||||
searchLog: 6,
|
||||
minMatch: 5,
|
||||
targetLength: 16,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 22,
|
||||
hashLog: 23,
|
||||
searchLog: 6,
|
||||
minMatch: 5,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 22,
|
||||
hashLog: 22,
|
||||
searchLog: 4,
|
||||
minMatch: 5,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 22,
|
||||
hashLog: 23,
|
||||
searchLog: 5,
|
||||
minMatch: 5,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 23,
|
||||
hashLog: 23,
|
||||
searchLog: 6,
|
||||
minMatch: 5,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 22,
|
||||
chainLog: 22,
|
||||
hashLog: 22,
|
||||
searchLog: 5,
|
||||
minMatch: 5,
|
||||
targetLength: 48,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 23,
|
||||
chainLog: 23,
|
||||
hashLog: 22,
|
||||
searchLog: 5,
|
||||
minMatch: 4,
|
||||
targetLength: 64,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 23,
|
||||
chainLog: 23,
|
||||
hashLog: 22,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 64,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 23,
|
||||
chainLog: 24,
|
||||
hashLog: 22,
|
||||
searchLog: 7,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 25,
|
||||
chainLog: 25,
|
||||
hashLog: 23,
|
||||
searchLog: 7,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 26,
|
||||
chainLog: 26,
|
||||
hashLog: 24,
|
||||
searchLog: 7,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 27,
|
||||
chainLog: 27,
|
||||
hashLog: 25,
|
||||
searchLog: 9,
|
||||
minMatch: 3,
|
||||
targetLength: 999,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
},
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 12,
|
||||
hashLog: 13,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 1,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 13,
|
||||
hashLog: 14,
|
||||
searchLog: 1,
|
||||
minMatch: 6,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 14,
|
||||
hashLog: 14,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 16,
|
||||
hashLog: 16,
|
||||
searchLog: 1,
|
||||
minMatch: 4,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 3,
|
||||
minMatch: 5,
|
||||
targetLength: 2,
|
||||
strategy: ZSTD_strategy.ZSTD_greedy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 17,
|
||||
hashLog: 18,
|
||||
searchLog: 5,
|
||||
minMatch: 5,
|
||||
targetLength: 2,
|
||||
strategy: ZSTD_strategy.ZSTD_greedy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 3,
|
||||
minMatch: 5,
|
||||
targetLength: 4,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 4,
|
||||
minMatch: 4,
|
||||
targetLength: 4,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 4,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 5,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 6,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 5,
|
||||
minMatch: 4,
|
||||
targetLength: 12,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 7,
|
||||
minMatch: 4,
|
||||
targetLength: 12,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 4,
|
||||
minMatch: 4,
|
||||
targetLength: 16,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 4,
|
||||
minMatch: 3,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 18,
|
||||
hashLog: 19,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 128,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 128,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 8,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 128,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 8,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 10,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 12,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 18,
|
||||
chainLog: 19,
|
||||
hashLog: 19,
|
||||
searchLog: 13,
|
||||
minMatch: 3,
|
||||
targetLength: 999,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
},
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 12,
|
||||
hashLog: 12,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 1,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 12,
|
||||
hashLog: 13,
|
||||
searchLog: 1,
|
||||
minMatch: 6,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 13,
|
||||
hashLog: 15,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 15,
|
||||
hashLog: 16,
|
||||
searchLog: 2,
|
||||
minMatch: 5,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 17,
|
||||
hashLog: 17,
|
||||
searchLog: 2,
|
||||
minMatch: 4,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 3,
|
||||
minMatch: 4,
|
||||
targetLength: 2,
|
||||
strategy: ZSTD_strategy.ZSTD_greedy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 3,
|
||||
minMatch: 4,
|
||||
targetLength: 4,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 3,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 4,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 5,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 16,
|
||||
hashLog: 17,
|
||||
searchLog: 6,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 17,
|
||||
hashLog: 17,
|
||||
searchLog: 5,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 7,
|
||||
minMatch: 4,
|
||||
targetLength: 12,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 3,
|
||||
minMatch: 4,
|
||||
targetLength: 12,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 4,
|
||||
minMatch: 3,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 128,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 8,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 10,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 5,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 7,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 9,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 17,
|
||||
chainLog: 18,
|
||||
hashLog: 17,
|
||||
searchLog: 11,
|
||||
minMatch: 3,
|
||||
targetLength: 999,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
},
|
||||
new ZSTD_compressionParameters[23]
|
||||
{
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 12,
|
||||
hashLog: 13,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 1,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 15,
|
||||
searchLog: 1,
|
||||
minMatch: 5,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 15,
|
||||
searchLog: 1,
|
||||
minMatch: 4,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_fast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 15,
|
||||
searchLog: 2,
|
||||
minMatch: 4,
|
||||
targetLength: 0,
|
||||
strategy: ZSTD_strategy.ZSTD_dfast
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 14,
|
||||
searchLog: 4,
|
||||
minMatch: 4,
|
||||
targetLength: 2,
|
||||
strategy: ZSTD_strategy.ZSTD_greedy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 14,
|
||||
searchLog: 3,
|
||||
minMatch: 4,
|
||||
targetLength: 4,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 14,
|
||||
searchLog: 4,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 14,
|
||||
searchLog: 6,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 14,
|
||||
hashLog: 14,
|
||||
searchLog: 8,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_lazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 14,
|
||||
searchLog: 5,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 14,
|
||||
searchLog: 9,
|
||||
minMatch: 4,
|
||||
targetLength: 8,
|
||||
strategy: ZSTD_strategy.ZSTD_btlazy2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 14,
|
||||
searchLog: 3,
|
||||
minMatch: 4,
|
||||
targetLength: 12,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 14,
|
||||
searchLog: 4,
|
||||
minMatch: 3,
|
||||
targetLength: 24,
|
||||
strategy: ZSTD_strategy.ZSTD_btopt
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 14,
|
||||
searchLog: 5,
|
||||
minMatch: 3,
|
||||
targetLength: 32,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 64,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 7,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 5,
|
||||
minMatch: 3,
|
||||
targetLength: 48,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 6,
|
||||
minMatch: 3,
|
||||
targetLength: 128,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 7,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 8,
|
||||
minMatch: 3,
|
||||
targetLength: 256,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 8,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 9,
|
||||
minMatch: 3,
|
||||
targetLength: 512,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
new ZSTD_compressionParameters(
|
||||
windowLog: 14,
|
||||
chainLog: 15,
|
||||
hashLog: 15,
|
||||
searchLog: 10,
|
||||
minMatch: 3,
|
||||
targetLength: 999,
|
||||
strategy: ZSTD_strategy.ZSTD_btultra2
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,4 @@ namespace ZstdSharp.Unsafe
|
||||
return add > 0 ? ptr + add : ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace ZstdSharp.Unsafe
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
private static int g_displayLevel = 0;
|
||||
|
||||
/**
|
||||
* Returns the sum of the sample sizes.
|
||||
*/
|
||||
@@ -23,7 +24,11 @@ namespace ZstdSharp.Unsafe
|
||||
/**
|
||||
* Warns the user when their corpus is too small.
|
||||
*/
|
||||
private static void COVER_warnOnSmallCorpus(nuint maxDictSize, nuint nbDmers, int displayLevel)
|
||||
private static void COVER_warnOnSmallCorpus(
|
||||
nuint maxDictSize,
|
||||
nuint nbDmers,
|
||||
int displayLevel
|
||||
)
|
||||
{
|
||||
double ratio = nbDmers / (double)maxDictSize;
|
||||
if (ratio >= 10)
|
||||
@@ -45,7 +50,12 @@ namespace ZstdSharp.Unsafe
|
||||
* @param passes The target number of passes over the dmer corpus.
|
||||
* More passes means a better dictionary.
|
||||
*/
|
||||
private static COVER_epoch_info_t COVER_computeEpochs(uint maxDictSize, uint nbDmers, uint k, uint passes)
|
||||
private static COVER_epoch_info_t COVER_computeEpochs(
|
||||
uint maxDictSize,
|
||||
uint nbDmers,
|
||||
uint k,
|
||||
uint passes
|
||||
)
|
||||
{
|
||||
uint minEpochSize = k * 10;
|
||||
COVER_epoch_info_t epochs;
|
||||
@@ -66,7 +76,16 @@ namespace ZstdSharp.Unsafe
|
||||
/**
|
||||
* Checks total compressed size of a dictionary
|
||||
*/
|
||||
private static nuint COVER_checkTotalCompressedSize(ZDICT_cover_params_t parameters, nuint* samplesSizes, byte* samples, nuint* offsets, nuint nbTrainSamples, nuint nbSamples, byte* dict, nuint dictBufferCapacity)
|
||||
private static nuint COVER_checkTotalCompressedSize(
|
||||
ZDICT_cover_params_t parameters,
|
||||
nuint* samplesSizes,
|
||||
byte* samples,
|
||||
nuint* offsets,
|
||||
nuint nbTrainSamples,
|
||||
nuint nbSamples,
|
||||
byte* dict,
|
||||
nuint dictBufferCapacity
|
||||
)
|
||||
{
|
||||
nuint totalCompressedSize = unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC));
|
||||
/* Pointers */
|
||||
@@ -81,7 +100,8 @@ namespace ZstdSharp.Unsafe
|
||||
i = parameters.splitPoint < 1 ? nbTrainSamples : 0;
|
||||
for (; i < nbSamples; ++i)
|
||||
{
|
||||
maxSampleSize = samplesSizes[i] > maxSampleSize ? samplesSizes[i] : maxSampleSize;
|
||||
maxSampleSize =
|
||||
samplesSizes[i] > maxSampleSize ? samplesSizes[i] : maxSampleSize;
|
||||
}
|
||||
|
||||
dstCapacity = ZSTD_compressBound(maxSampleSize);
|
||||
@@ -99,7 +119,14 @@ namespace ZstdSharp.Unsafe
|
||||
i = parameters.splitPoint < 1 ? nbTrainSamples : 0;
|
||||
for (; i < nbSamples; ++i)
|
||||
{
|
||||
nuint size = ZSTD_compress_usingCDict(cctx, dst, dstCapacity, samples + offsets[i], samplesSizes[i], cdict);
|
||||
nuint size = ZSTD_compress_usingCDict(
|
||||
cctx,
|
||||
dst,
|
||||
dstCapacity,
|
||||
samples + offsets[i],
|
||||
samplesSizes[i],
|
||||
cdict
|
||||
);
|
||||
if (ERR_isError(size))
|
||||
{
|
||||
totalCompressedSize = size;
|
||||
@@ -109,7 +136,7 @@ namespace ZstdSharp.Unsafe
|
||||
totalCompressedSize += size;
|
||||
}
|
||||
|
||||
_compressCleanup:
|
||||
_compressCleanup:
|
||||
ZSTD_freeCCtx(cctx);
|
||||
ZSTD_freeCDict(cdict);
|
||||
if (dst != null)
|
||||
@@ -194,7 +221,11 @@ namespace ZstdSharp.Unsafe
|
||||
* Decrements liveJobs and signals any waiting threads if liveJobs == 0.
|
||||
* If this dictionary is the best so far save it and its parameters.
|
||||
*/
|
||||
private static void COVER_best_finish(COVER_best_s* best, ZDICT_cover_params_t parameters, COVER_dictSelection selection)
|
||||
private static void COVER_best_finish(
|
||||
COVER_best_s* best,
|
||||
ZDICT_cover_params_t parameters,
|
||||
COVER_dictSelection selection
|
||||
)
|
||||
{
|
||||
void* dict = selection.dictContent;
|
||||
nuint compressedSize = selection.totalCompressedSize;
|
||||
@@ -221,7 +252,9 @@ namespace ZstdSharp.Unsafe
|
||||
best->dict = malloc(dictSize);
|
||||
if (best->dict == null)
|
||||
{
|
||||
best->compressedSize = unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC));
|
||||
best->compressedSize = unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC)
|
||||
);
|
||||
best->dictSize = 0;
|
||||
SynchronizationWrapper.Pulse(&best->mutex);
|
||||
SynchronizationWrapper.Exit(&best->mutex);
|
||||
@@ -271,7 +304,9 @@ namespace ZstdSharp.Unsafe
|
||||
*/
|
||||
private static uint COVER_dictSelectionIsError(COVER_dictSelection selection)
|
||||
{
|
||||
return ERR_isError(selection.totalCompressedSize) || selection.dictContent == null ? 1U : 0U;
|
||||
return ERR_isError(selection.totalCompressedSize) || selection.dictContent == null
|
||||
? 1U
|
||||
: 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,7 +324,19 @@ namespace ZstdSharp.Unsafe
|
||||
* smallest dictionary within a specified regression of the compressed size
|
||||
* from the largest dictionary.
|
||||
*/
|
||||
private static COVER_dictSelection COVER_selectDict(byte* customDictContent, nuint dictBufferCapacity, nuint dictContentSize, byte* samplesBuffer, nuint* samplesSizes, uint nbFinalizeSamples, nuint nbCheckSamples, nuint nbSamples, ZDICT_cover_params_t @params, nuint* offsets, nuint totalCompressedSize)
|
||||
private static COVER_dictSelection COVER_selectDict(
|
||||
byte* customDictContent,
|
||||
nuint dictBufferCapacity,
|
||||
nuint dictContentSize,
|
||||
byte* samplesBuffer,
|
||||
nuint* samplesSizes,
|
||||
uint nbFinalizeSamples,
|
||||
nuint nbCheckSamples,
|
||||
nuint nbSamples,
|
||||
ZDICT_cover_params_t @params,
|
||||
nuint* offsets,
|
||||
nuint totalCompressedSize
|
||||
)
|
||||
{
|
||||
nuint largestDict = 0;
|
||||
nuint largestCompressed = 0;
|
||||
@@ -305,7 +352,16 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
memcpy(largestDictbuffer, customDictContent, (uint)dictContentSize);
|
||||
dictContentSize = ZDICT_finalizeDictionary(largestDictbuffer, dictBufferCapacity, customDictContent, dictContentSize, samplesBuffer, samplesSizes, nbFinalizeSamples, @params.zParams);
|
||||
dictContentSize = ZDICT_finalizeDictionary(
|
||||
largestDictbuffer,
|
||||
dictBufferCapacity,
|
||||
customDictContent,
|
||||
dictContentSize,
|
||||
samplesBuffer,
|
||||
samplesSizes,
|
||||
nbFinalizeSamples,
|
||||
@params.zParams
|
||||
);
|
||||
if (ZDICT_isError(dictContentSize))
|
||||
{
|
||||
free(largestDictbuffer);
|
||||
@@ -313,7 +369,16 @@ namespace ZstdSharp.Unsafe
|
||||
return COVER_dictSelectionError(dictContentSize);
|
||||
}
|
||||
|
||||
totalCompressedSize = COVER_checkTotalCompressedSize(@params, samplesSizes, samplesBuffer, offsets, nbCheckSamples, nbSamples, largestDictbuffer, dictContentSize);
|
||||
totalCompressedSize = COVER_checkTotalCompressedSize(
|
||||
@params,
|
||||
samplesSizes,
|
||||
samplesBuffer,
|
||||
offsets,
|
||||
nbCheckSamples,
|
||||
nbSamples,
|
||||
largestDictbuffer,
|
||||
dictContentSize
|
||||
);
|
||||
if (ERR_isError(totalCompressedSize))
|
||||
{
|
||||
free(largestDictbuffer);
|
||||
@@ -333,7 +398,16 @@ namespace ZstdSharp.Unsafe
|
||||
while (dictContentSize < largestDict)
|
||||
{
|
||||
memcpy(candidateDictBuffer, largestDictbuffer, (uint)largestDict);
|
||||
dictContentSize = ZDICT_finalizeDictionary(candidateDictBuffer, dictBufferCapacity, customDictContentEnd - dictContentSize, dictContentSize, samplesBuffer, samplesSizes, nbFinalizeSamples, @params.zParams);
|
||||
dictContentSize = ZDICT_finalizeDictionary(
|
||||
candidateDictBuffer,
|
||||
dictBufferCapacity,
|
||||
customDictContentEnd - dictContentSize,
|
||||
dictContentSize,
|
||||
samplesBuffer,
|
||||
samplesSizes,
|
||||
nbFinalizeSamples,
|
||||
@params.zParams
|
||||
);
|
||||
if (ZDICT_isError(dictContentSize))
|
||||
{
|
||||
free(largestDictbuffer);
|
||||
@@ -341,7 +415,16 @@ namespace ZstdSharp.Unsafe
|
||||
return COVER_dictSelectionError(dictContentSize);
|
||||
}
|
||||
|
||||
totalCompressedSize = COVER_checkTotalCompressedSize(@params, samplesSizes, samplesBuffer, offsets, nbCheckSamples, nbSamples, candidateDictBuffer, dictContentSize);
|
||||
totalCompressedSize = COVER_checkTotalCompressedSize(
|
||||
@params,
|
||||
samplesSizes,
|
||||
samplesBuffer,
|
||||
offsets,
|
||||
nbCheckSamples,
|
||||
nbSamples,
|
||||
candidateDictBuffer,
|
||||
dictContentSize
|
||||
);
|
||||
if (ERR_isError(totalCompressedSize))
|
||||
{
|
||||
free(largestDictbuffer);
|
||||
@@ -352,7 +435,11 @@ namespace ZstdSharp.Unsafe
|
||||
if (totalCompressedSize <= largestCompressed * regressionTolerance)
|
||||
{
|
||||
free(largestDictbuffer);
|
||||
return setDictSelection(candidateDictBuffer, dictContentSize, totalCompressedSize);
|
||||
return setDictSelection(
|
||||
candidateDictBuffer,
|
||||
dictContentSize,
|
||||
totalCompressedSize
|
||||
);
|
||||
}
|
||||
|
||||
dictContentSize *= 2;
|
||||
@@ -364,4 +451,4 @@ namespace ZstdSharp.Unsafe
|
||||
return setDictSelection(largestDictbuffer, dictContentSize, totalCompressedSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ namespace ZstdSharp.Unsafe
|
||||
public byte tableLog;
|
||||
public byte reserved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* dictionary */
|
||||
public ZSTD_CDict_s* dict;
|
||||
|
||||
/* working context */
|
||||
public ZSTD_CCtx_s* zc;
|
||||
|
||||
/* must be ZSTD_BLOCKSIZE_MAX allocated */
|
||||
public void* workPlace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,13 @@ namespace ZstdSharp.Unsafe
|
||||
* FSE NCount encoding-decoding
|
||||
****************************************************************/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint FSE_readNCount_body(short* normalizedCounter, uint* maxSVPtr, uint* tableLogPtr, void* headerBuffer, nuint hbSize)
|
||||
private static nuint FSE_readNCount_body(
|
||||
short* normalizedCounter,
|
||||
uint* maxSVPtr,
|
||||
uint* tableLogPtr,
|
||||
void* headerBuffer,
|
||||
nuint hbSize
|
||||
)
|
||||
{
|
||||
byte* istart = (byte*)headerBuffer;
|
||||
byte* iend = istart + hbSize;
|
||||
@@ -57,11 +63,19 @@ namespace ZstdSharp.Unsafe
|
||||
memset(buffer, 0, sizeof(sbyte) * 8);
|
||||
memcpy(buffer, headerBuffer, (uint)hbSize);
|
||||
{
|
||||
nuint countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr, buffer, sizeof(sbyte) * 8);
|
||||
nuint countSize = FSE_readNCount(
|
||||
normalizedCounter,
|
||||
maxSVPtr,
|
||||
tableLogPtr,
|
||||
buffer,
|
||||
sizeof(sbyte) * 8
|
||||
);
|
||||
if (FSE_isError(countSize))
|
||||
return countSize;
|
||||
if (countSize > hbSize)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)
|
||||
);
|
||||
return countSize;
|
||||
}
|
||||
}
|
||||
@@ -198,17 +212,42 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
/* Avoids the FORCE_INLINE of the _body() function. */
|
||||
private static nuint FSE_readNCount_body_default(short* normalizedCounter, uint* maxSVPtr, uint* tableLogPtr, void* headerBuffer, nuint hbSize)
|
||||
private static nuint FSE_readNCount_body_default(
|
||||
short* normalizedCounter,
|
||||
uint* maxSVPtr,
|
||||
uint* tableLogPtr,
|
||||
void* headerBuffer,
|
||||
nuint hbSize
|
||||
)
|
||||
{
|
||||
return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
||||
return FSE_readNCount_body(
|
||||
normalizedCounter,
|
||||
maxSVPtr,
|
||||
tableLogPtr,
|
||||
headerBuffer,
|
||||
hbSize
|
||||
);
|
||||
}
|
||||
|
||||
/*! FSE_readNCount_bmi2():
|
||||
* Same as FSE_readNCount() but pass bmi2=1 when your CPU supports BMI2 and 0 otherwise.
|
||||
*/
|
||||
private static nuint FSE_readNCount_bmi2(short* normalizedCounter, uint* maxSVPtr, uint* tableLogPtr, void* headerBuffer, nuint hbSize, int bmi2)
|
||||
private static nuint FSE_readNCount_bmi2(
|
||||
short* normalizedCounter,
|
||||
uint* maxSVPtr,
|
||||
uint* tableLogPtr,
|
||||
void* headerBuffer,
|
||||
nuint hbSize,
|
||||
int bmi2
|
||||
)
|
||||
{
|
||||
return FSE_readNCount_body_default(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
||||
return FSE_readNCount_body_default(
|
||||
normalizedCounter,
|
||||
maxSVPtr,
|
||||
tableLogPtr,
|
||||
headerBuffer,
|
||||
hbSize
|
||||
);
|
||||
}
|
||||
|
||||
/*! FSE_readNCount():
|
||||
@@ -216,9 +255,22 @@ namespace ZstdSharp.Unsafe
|
||||
@return : size read from 'rBuffer',
|
||||
or an errorCode, which can be tested using FSE_isError().
|
||||
maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */
|
||||
private static nuint FSE_readNCount(short* normalizedCounter, uint* maxSVPtr, uint* tableLogPtr, void* headerBuffer, nuint hbSize)
|
||||
private static nuint FSE_readNCount(
|
||||
short* normalizedCounter,
|
||||
uint* maxSVPtr,
|
||||
uint* tableLogPtr,
|
||||
void* headerBuffer,
|
||||
nuint hbSize
|
||||
)
|
||||
{
|
||||
return FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize, 0);
|
||||
return FSE_readNCount_bmi2(
|
||||
normalizedCounter,
|
||||
maxSVPtr,
|
||||
tableLogPtr,
|
||||
headerBuffer,
|
||||
hbSize,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/*! HUF_readStats() :
|
||||
@@ -228,14 +280,44 @@ namespace ZstdSharp.Unsafe
|
||||
@return : size read from `src` , or an error Code .
|
||||
Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
|
||||
*/
|
||||
private static nuint HUF_readStats(byte* huffWeight, nuint hwSize, uint* rankStats, uint* nbSymbolsPtr, uint* tableLogPtr, void* src, nuint srcSize)
|
||||
private static nuint HUF_readStats(
|
||||
byte* huffWeight,
|
||||
nuint hwSize,
|
||||
uint* rankStats,
|
||||
uint* nbSymbolsPtr,
|
||||
uint* tableLogPtr,
|
||||
void* src,
|
||||
nuint srcSize
|
||||
)
|
||||
{
|
||||
uint* wksp = stackalloc uint[219];
|
||||
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(uint) * 219, 0);
|
||||
return HUF_readStats_wksp(
|
||||
huffWeight,
|
||||
hwSize,
|
||||
rankStats,
|
||||
nbSymbolsPtr,
|
||||
tableLogPtr,
|
||||
src,
|
||||
srcSize,
|
||||
wksp,
|
||||
sizeof(uint) * 219,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint HUF_readStats_body(byte* huffWeight, nuint hwSize, uint* rankStats, uint* nbSymbolsPtr, uint* tableLogPtr, void* src, nuint srcSize, void* workSpace, nuint wkspSize, int bmi2)
|
||||
private static nuint HUF_readStats_body(
|
||||
byte* huffWeight,
|
||||
nuint hwSize,
|
||||
uint* rankStats,
|
||||
uint* nbSymbolsPtr,
|
||||
uint* tableLogPtr,
|
||||
void* src,
|
||||
nuint srcSize,
|
||||
void* workSpace,
|
||||
nuint wkspSize,
|
||||
int bmi2
|
||||
)
|
||||
{
|
||||
uint weightTotal;
|
||||
byte* ip = (byte*)src;
|
||||
@@ -266,7 +348,16 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
if (iSize + 1 > srcSize)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_srcSize_wrong));
|
||||
oSize = FSE_decompress_wksp_bmi2(huffWeight, hwSize - 1, ip + 1, iSize, 6, workSpace, wkspSize, bmi2);
|
||||
oSize = FSE_decompress_wksp_bmi2(
|
||||
huffWeight,
|
||||
hwSize - 1,
|
||||
ip + 1,
|
||||
iSize,
|
||||
6,
|
||||
workSpace,
|
||||
wkspSize,
|
||||
bmi2
|
||||
);
|
||||
if (FSE_isError(oSize))
|
||||
return oSize;
|
||||
}
|
||||
@@ -278,7 +369,9 @@ namespace ZstdSharp.Unsafe
|
||||
for (n = 0; n < oSize; n++)
|
||||
{
|
||||
if (huffWeight[n] > 12)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)
|
||||
);
|
||||
rankStats[huffWeight[n]]++;
|
||||
weightTotal += (uint)(1 << huffWeight[n] >> 1);
|
||||
}
|
||||
@@ -297,7 +390,9 @@ namespace ZstdSharp.Unsafe
|
||||
uint verif = (uint)(1 << (int)ZSTD_highbit32(rest));
|
||||
uint lastWeight = ZSTD_highbit32(rest) + 1;
|
||||
if (verif != rest)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)
|
||||
);
|
||||
huffWeight[oSize] = (byte)lastWeight;
|
||||
rankStats[lastWeight]++;
|
||||
}
|
||||
@@ -310,14 +405,56 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
/* Avoids the FORCE_INLINE of the _body() function. */
|
||||
private static nuint HUF_readStats_body_default(byte* huffWeight, nuint hwSize, uint* rankStats, uint* nbSymbolsPtr, uint* tableLogPtr, void* src, nuint srcSize, void* workSpace, nuint wkspSize)
|
||||
private static nuint HUF_readStats_body_default(
|
||||
byte* huffWeight,
|
||||
nuint hwSize,
|
||||
uint* rankStats,
|
||||
uint* nbSymbolsPtr,
|
||||
uint* tableLogPtr,
|
||||
void* src,
|
||||
nuint srcSize,
|
||||
void* workSpace,
|
||||
nuint wkspSize
|
||||
)
|
||||
{
|
||||
return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 0);
|
||||
return HUF_readStats_body(
|
||||
huffWeight,
|
||||
hwSize,
|
||||
rankStats,
|
||||
nbSymbolsPtr,
|
||||
tableLogPtr,
|
||||
src,
|
||||
srcSize,
|
||||
workSpace,
|
||||
wkspSize,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
private static nuint HUF_readStats_wksp(byte* huffWeight, nuint hwSize, uint* rankStats, uint* nbSymbolsPtr, uint* tableLogPtr, void* src, nuint srcSize, void* workSpace, nuint wkspSize, int flags)
|
||||
private static nuint HUF_readStats_wksp(
|
||||
byte* huffWeight,
|
||||
nuint hwSize,
|
||||
uint* rankStats,
|
||||
uint* nbSymbolsPtr,
|
||||
uint* tableLogPtr,
|
||||
void* src,
|
||||
nuint srcSize,
|
||||
void* workSpace,
|
||||
nuint wkspSize,
|
||||
int flags
|
||||
)
|
||||
{
|
||||
return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
||||
return HUF_readStats_body_default(
|
||||
huffWeight,
|
||||
hwSize,
|
||||
rankStats,
|
||||
nbSymbolsPtr,
|
||||
tableLogPtr,
|
||||
src,
|
||||
srcSize,
|
||||
workSpace,
|
||||
wkspSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,4 +108,4 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint estLitSize;
|
||||
public nuint estBlockSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* Percentage of training samples used for ZDICT_finalizeDictionary */
|
||||
public uint finalize;
|
||||
|
||||
/* Number of dmer skipped between each dmer counted in computeFrequency */
|
||||
public uint skip;
|
||||
|
||||
public FASTCOVER_accel_t(uint finalize, uint skip)
|
||||
{
|
||||
this.finalize = finalize;
|
||||
this.skip = skip;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint f;
|
||||
public FASTCOVER_accel_t accelParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint dictBufferCapacity;
|
||||
public ZDICT_cover_params_t parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace ZstdSharp.Unsafe
|
||||
public Fingerprint pastEvents;
|
||||
public Fingerprint newEvents;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@ namespace ZstdSharp.Unsafe
|
||||
public void* symbolTT;
|
||||
public uint stateLog;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace ZstdSharp.Unsafe
|
||||
public unsafe struct FSE_DState_t
|
||||
{
|
||||
public nuint state;
|
||||
|
||||
/* precise table may vary, depending on U16 */
|
||||
public void* table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace ZstdSharp.Unsafe
|
||||
public ushort tableLog;
|
||||
public ushort fastMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public fixed short ncount[256];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace ZstdSharp.Unsafe
|
||||
public byte symbol;
|
||||
public byte nbBits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/**< Cannot use the previous table */
|
||||
FSE_repeat_none,
|
||||
|
||||
/**< Can use the previous table but it must be checked */
|
||||
FSE_repeat_check,
|
||||
|
||||
/**< Can use the previous table and it is assumed to be valid */
|
||||
FSE_repeat_valid
|
||||
FSE_repeat_valid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ namespace ZstdSharp.Unsafe
|
||||
public int deltaFindState;
|
||||
public uint deltaNbBits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,24 @@ namespace ZstdSharp.Unsafe
|
||||
return ZSTD_hash8Ptr(p, f);
|
||||
}
|
||||
|
||||
private static readonly FASTCOVER_accel_t* FASTCOVER_defaultAccelParameters = GetArrayPointer(new FASTCOVER_accel_t[11] { new FASTCOVER_accel_t(finalize: 100, skip: 0), new FASTCOVER_accel_t(finalize: 100, skip: 0), new FASTCOVER_accel_t(finalize: 50, skip: 1), new FASTCOVER_accel_t(finalize: 34, skip: 2), new FASTCOVER_accel_t(finalize: 25, skip: 3), new FASTCOVER_accel_t(finalize: 20, skip: 4), new FASTCOVER_accel_t(finalize: 17, skip: 5), new FASTCOVER_accel_t(finalize: 14, skip: 6), new FASTCOVER_accel_t(finalize: 13, skip: 7), new FASTCOVER_accel_t(finalize: 11, skip: 8), new FASTCOVER_accel_t(finalize: 10, skip: 9) });
|
||||
private static readonly FASTCOVER_accel_t* FASTCOVER_defaultAccelParameters =
|
||||
GetArrayPointer(
|
||||
new FASTCOVER_accel_t[11]
|
||||
{
|
||||
new FASTCOVER_accel_t(finalize: 100, skip: 0),
|
||||
new FASTCOVER_accel_t(finalize: 100, skip: 0),
|
||||
new FASTCOVER_accel_t(finalize: 50, skip: 1),
|
||||
new FASTCOVER_accel_t(finalize: 34, skip: 2),
|
||||
new FASTCOVER_accel_t(finalize: 25, skip: 3),
|
||||
new FASTCOVER_accel_t(finalize: 20, skip: 4),
|
||||
new FASTCOVER_accel_t(finalize: 17, skip: 5),
|
||||
new FASTCOVER_accel_t(finalize: 14, skip: 6),
|
||||
new FASTCOVER_accel_t(finalize: 13, skip: 7),
|
||||
new FASTCOVER_accel_t(finalize: 11, skip: 8),
|
||||
new FASTCOVER_accel_t(finalize: 10, skip: 9),
|
||||
}
|
||||
);
|
||||
|
||||
/*-*************************************
|
||||
* Helper functions
|
||||
***************************************/
|
||||
@@ -35,7 +52,14 @@ namespace ZstdSharp.Unsafe
|
||||
*
|
||||
* Once the dmer with hash value d is in the dictionary we set F(d) = 0.
|
||||
*/
|
||||
private static COVER_segment_t FASTCOVER_selectSegment(FASTCOVER_ctx_t* ctx, uint* freqs, uint begin, uint end, ZDICT_cover_params_t parameters, ushort* segmentFreqs)
|
||||
private static COVER_segment_t FASTCOVER_selectSegment(
|
||||
FASTCOVER_ctx_t* ctx,
|
||||
uint* freqs,
|
||||
uint begin,
|
||||
uint end,
|
||||
ZDICT_cover_params_t parameters,
|
||||
ushort* segmentFreqs
|
||||
)
|
||||
{
|
||||
/* Constants */
|
||||
uint k = parameters.k;
|
||||
@@ -47,7 +71,7 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
begin = 0,
|
||||
end = 0,
|
||||
score = 0
|
||||
score = 0,
|
||||
};
|
||||
COVER_segment_t activeSegment;
|
||||
activeSegment.begin = begin;
|
||||
@@ -67,7 +91,11 @@ namespace ZstdSharp.Unsafe
|
||||
if (activeSegment.end - activeSegment.begin == dmersInK + 1)
|
||||
{
|
||||
/* Get hash value of the dmer to be eliminated from active segment */
|
||||
nuint delIndex = FASTCOVER_hashPtrToIndex(ctx->samples + activeSegment.begin, f, d);
|
||||
nuint delIndex = FASTCOVER_hashPtrToIndex(
|
||||
ctx->samples + activeSegment.begin,
|
||||
f,
|
||||
d
|
||||
);
|
||||
segmentFreqs[delIndex] -= 1;
|
||||
if (segmentFreqs[delIndex] == 0)
|
||||
{
|
||||
@@ -103,7 +131,12 @@ namespace ZstdSharp.Unsafe
|
||||
return bestSegment;
|
||||
}
|
||||
|
||||
private static int FASTCOVER_checkParameters(ZDICT_cover_params_t parameters, nuint maxDictSize, uint f, uint accel)
|
||||
private static int FASTCOVER_checkParameters(
|
||||
ZDICT_cover_params_t parameters,
|
||||
nuint maxDictSize,
|
||||
uint f,
|
||||
uint accel
|
||||
)
|
||||
{
|
||||
if (parameters.d == 0 || parameters.k == 0)
|
||||
{
|
||||
@@ -189,16 +222,32 @@ namespace ZstdSharp.Unsafe
|
||||
* Returns 0 on success or error code on error.
|
||||
* The context must be destroyed with `FASTCOVER_ctx_destroy()`.
|
||||
*/
|
||||
private static nuint FASTCOVER_ctx_init(FASTCOVER_ctx_t* ctx, void* samplesBuffer, nuint* samplesSizes, uint nbSamples, uint d, double splitPoint, uint f, FASTCOVER_accel_t accelParams)
|
||||
private static nuint FASTCOVER_ctx_init(
|
||||
FASTCOVER_ctx_t* ctx,
|
||||
void* samplesBuffer,
|
||||
nuint* samplesSizes,
|
||||
uint nbSamples,
|
||||
uint d,
|
||||
double splitPoint,
|
||||
uint f,
|
||||
FASTCOVER_accel_t accelParams
|
||||
)
|
||||
{
|
||||
byte* samples = (byte*)samplesBuffer;
|
||||
nuint totalSamplesSize = COVER_sum(samplesSizes, nbSamples);
|
||||
/* Split samples into testing and training sets */
|
||||
uint nbTrainSamples = splitPoint < 1 ? (uint)(nbSamples * splitPoint) : nbSamples;
|
||||
uint nbTestSamples = splitPoint < 1 ? nbSamples - nbTrainSamples : nbSamples;
|
||||
nuint trainingSamplesSize = splitPoint < 1 ? COVER_sum(samplesSizes, nbTrainSamples) : totalSamplesSize;
|
||||
nuint testSamplesSize = splitPoint < 1 ? COVER_sum(samplesSizes + nbTrainSamples, nbTestSamples) : totalSamplesSize;
|
||||
if (totalSamplesSize < (d > sizeof(ulong) ? d : sizeof(ulong)) || totalSamplesSize >= (sizeof(nuint) == 8 ? unchecked((uint)-1) : 1 * (1U << 30)))
|
||||
nuint trainingSamplesSize =
|
||||
splitPoint < 1 ? COVER_sum(samplesSizes, nbTrainSamples) : totalSamplesSize;
|
||||
nuint testSamplesSize =
|
||||
splitPoint < 1
|
||||
? COVER_sum(samplesSizes + nbTrainSamples, nbTestSamples)
|
||||
: totalSamplesSize;
|
||||
if (
|
||||
totalSamplesSize < (d > sizeof(ulong) ? d : sizeof(ulong))
|
||||
|| totalSamplesSize >= (sizeof(nuint) == 8 ? unchecked((uint)-1) : 1 * (1U << 30))
|
||||
)
|
||||
{
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_srcSize_wrong));
|
||||
}
|
||||
@@ -224,7 +273,7 @@ namespace ZstdSharp.Unsafe
|
||||
d = d,
|
||||
f = f,
|
||||
accelParams = accelParams,
|
||||
offsets = (nuint*)calloc(nbSamples + 1, (ulong)sizeof(nuint))
|
||||
offsets = (nuint*)calloc(nbSamples + 1, (ulong)sizeof(nuint)),
|
||||
};
|
||||
if (ctx->offsets == null)
|
||||
{
|
||||
@@ -256,12 +305,24 @@ namespace ZstdSharp.Unsafe
|
||||
/**
|
||||
* Given the prepared context build the dictionary.
|
||||
*/
|
||||
private static nuint FASTCOVER_buildDictionary(FASTCOVER_ctx_t* ctx, uint* freqs, void* dictBuffer, nuint dictBufferCapacity, ZDICT_cover_params_t parameters, ushort* segmentFreqs)
|
||||
private static nuint FASTCOVER_buildDictionary(
|
||||
FASTCOVER_ctx_t* ctx,
|
||||
uint* freqs,
|
||||
void* dictBuffer,
|
||||
nuint dictBufferCapacity,
|
||||
ZDICT_cover_params_t parameters,
|
||||
ushort* segmentFreqs
|
||||
)
|
||||
{
|
||||
byte* dict = (byte*)dictBuffer;
|
||||
nuint tail = dictBufferCapacity;
|
||||
/* Divide the data into epochs. We will select one segment from each epoch. */
|
||||
COVER_epoch_info_t epochs = COVER_computeEpochs((uint)dictBufferCapacity, (uint)ctx->nbDmers, parameters.k, 1);
|
||||
COVER_epoch_info_t epochs = COVER_computeEpochs(
|
||||
(uint)dictBufferCapacity,
|
||||
(uint)ctx->nbDmers,
|
||||
parameters.k,
|
||||
1
|
||||
);
|
||||
const nuint maxZeroScoreRun = 10;
|
||||
nuint zeroScoreRun = 0;
|
||||
nuint epoch;
|
||||
@@ -271,7 +332,14 @@ namespace ZstdSharp.Unsafe
|
||||
uint epochEnd = epochBegin + epochs.size;
|
||||
nuint segmentSize;
|
||||
/* Select a segment */
|
||||
COVER_segment_t segment = FASTCOVER_selectSegment(ctx, freqs, epochBegin, epochEnd, parameters, segmentFreqs);
|
||||
COVER_segment_t segment = FASTCOVER_selectSegment(
|
||||
ctx,
|
||||
freqs,
|
||||
epochBegin,
|
||||
epochEnd,
|
||||
parameters,
|
||||
segmentFreqs
|
||||
);
|
||||
if (segment.score == 0)
|
||||
{
|
||||
if (++zeroScoreRun >= maxZeroScoreRun)
|
||||
@@ -283,7 +351,10 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
zeroScoreRun = 0;
|
||||
segmentSize = segment.end - segment.begin + parameters.d - 1 < tail ? segment.end - segment.begin + parameters.d - 1 : tail;
|
||||
segmentSize =
|
||||
segment.end - segment.begin + parameters.d - 1 < tail
|
||||
? segment.end - segment.begin + parameters.d - 1
|
||||
: tail;
|
||||
if (segmentSize < parameters.d)
|
||||
{
|
||||
break;
|
||||
@@ -313,7 +384,9 @@ namespace ZstdSharp.Unsafe
|
||||
ushort* segmentFreqs = (ushort*)calloc((ulong)1 << (int)ctx->f, sizeof(ushort));
|
||||
/* Allocate space for hash table, dict, and freqs */
|
||||
byte* dict = (byte*)malloc(dictBufferCapacity);
|
||||
COVER_dictSelection selection = COVER_dictSelectionError(unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC)));
|
||||
COVER_dictSelection selection = COVER_dictSelectionError(
|
||||
unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC))
|
||||
);
|
||||
uint* freqs = (uint*)malloc(((ulong)1 << (int)ctx->f) * sizeof(uint));
|
||||
if (segmentFreqs == null || dict == null || freqs == null)
|
||||
{
|
||||
@@ -322,16 +395,37 @@ namespace ZstdSharp.Unsafe
|
||||
|
||||
memcpy(freqs, ctx->freqs, (uint)(((ulong)1 << (int)ctx->f) * sizeof(uint)));
|
||||
{
|
||||
nuint tail = FASTCOVER_buildDictionary(ctx, freqs, dict, dictBufferCapacity, parameters, segmentFreqs);
|
||||
uint nbFinalizeSamples = (uint)(ctx->nbTrainSamples * ctx->accelParams.finalize / 100);
|
||||
selection = COVER_selectDict(dict + tail, dictBufferCapacity, dictBufferCapacity - tail, ctx->samples, ctx->samplesSizes, nbFinalizeSamples, ctx->nbTrainSamples, ctx->nbSamples, parameters, ctx->offsets, totalCompressedSize);
|
||||
nuint tail = FASTCOVER_buildDictionary(
|
||||
ctx,
|
||||
freqs,
|
||||
dict,
|
||||
dictBufferCapacity,
|
||||
parameters,
|
||||
segmentFreqs
|
||||
);
|
||||
uint nbFinalizeSamples = (uint)(
|
||||
ctx->nbTrainSamples * ctx->accelParams.finalize / 100
|
||||
);
|
||||
selection = COVER_selectDict(
|
||||
dict + tail,
|
||||
dictBufferCapacity,
|
||||
dictBufferCapacity - tail,
|
||||
ctx->samples,
|
||||
ctx->samplesSizes,
|
||||
nbFinalizeSamples,
|
||||
ctx->nbTrainSamples,
|
||||
ctx->nbSamples,
|
||||
parameters,
|
||||
ctx->offsets,
|
||||
totalCompressedSize
|
||||
);
|
||||
if (COVER_dictSelectionIsError(selection) != 0)
|
||||
{
|
||||
goto _cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
_cleanup:
|
||||
_cleanup:
|
||||
free(dict);
|
||||
COVER_best_finish(data->best, parameters, selection);
|
||||
free(data);
|
||||
@@ -340,7 +434,10 @@ namespace ZstdSharp.Unsafe
|
||||
free(freqs);
|
||||
}
|
||||
|
||||
private static void FASTCOVER_convertToCoverParams(ZDICT_fastCover_params_t fastCoverParams, ZDICT_cover_params_t* coverParams)
|
||||
private static void FASTCOVER_convertToCoverParams(
|
||||
ZDICT_fastCover_params_t fastCoverParams,
|
||||
ZDICT_cover_params_t* coverParams
|
||||
)
|
||||
{
|
||||
coverParams->k = fastCoverParams.k;
|
||||
coverParams->d = fastCoverParams.d;
|
||||
@@ -351,7 +448,12 @@ namespace ZstdSharp.Unsafe
|
||||
coverParams->shrinkDict = fastCoverParams.shrinkDict;
|
||||
}
|
||||
|
||||
private static void FASTCOVER_convertToFastCoverParams(ZDICT_cover_params_t coverParams, ZDICT_fastCover_params_t* fastCoverParams, uint f, uint accel)
|
||||
private static void FASTCOVER_convertToFastCoverParams(
|
||||
ZDICT_cover_params_t coverParams,
|
||||
ZDICT_fastCover_params_t* fastCoverParams,
|
||||
uint f,
|
||||
uint accel
|
||||
)
|
||||
{
|
||||
fastCoverParams->k = coverParams.k;
|
||||
fastCoverParams->d = coverParams.d;
|
||||
@@ -380,7 +482,14 @@ namespace ZstdSharp.Unsafe
|
||||
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
|
||||
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
||||
*/
|
||||
public static nuint ZDICT_trainFromBuffer_fastCover(void* dictBuffer, nuint dictBufferCapacity, void* samplesBuffer, nuint* samplesSizes, uint nbSamples, ZDICT_fastCover_params_t parameters)
|
||||
public static nuint ZDICT_trainFromBuffer_fastCover(
|
||||
void* dictBuffer,
|
||||
nuint dictBufferCapacity,
|
||||
void* samplesBuffer,
|
||||
nuint* samplesSizes,
|
||||
uint nbSamples,
|
||||
ZDICT_fastCover_params_t parameters
|
||||
)
|
||||
{
|
||||
byte* dict = (byte*)dictBuffer;
|
||||
FASTCOVER_ctx_t ctx;
|
||||
@@ -392,7 +501,14 @@ namespace ZstdSharp.Unsafe
|
||||
parameters.accel = parameters.accel == 0 ? 1 : parameters.accel;
|
||||
coverParams = new ZDICT_cover_params_t();
|
||||
FASTCOVER_convertToCoverParams(parameters, &coverParams);
|
||||
if (FASTCOVER_checkParameters(coverParams, dictBufferCapacity, parameters.f, parameters.accel) == 0)
|
||||
if (
|
||||
FASTCOVER_checkParameters(
|
||||
coverParams,
|
||||
dictBufferCapacity,
|
||||
parameters.f,
|
||||
parameters.accel
|
||||
) == 0
|
||||
)
|
||||
{
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound));
|
||||
}
|
||||
@@ -409,7 +525,16 @@ namespace ZstdSharp.Unsafe
|
||||
|
||||
accelParams = FASTCOVER_defaultAccelParameters[parameters.accel];
|
||||
{
|
||||
nuint initVal = FASTCOVER_ctx_init(&ctx, samplesBuffer, samplesSizes, nbSamples, coverParams.d, parameters.splitPoint, parameters.f, accelParams);
|
||||
nuint initVal = FASTCOVER_ctx_init(
|
||||
&ctx,
|
||||
samplesBuffer,
|
||||
samplesSizes,
|
||||
nbSamples,
|
||||
coverParams.d,
|
||||
parameters.splitPoint,
|
||||
parameters.f,
|
||||
accelParams
|
||||
);
|
||||
if (ERR_isError(initVal))
|
||||
{
|
||||
return initVal;
|
||||
@@ -419,13 +544,32 @@ namespace ZstdSharp.Unsafe
|
||||
COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.nbDmers, g_displayLevel);
|
||||
{
|
||||
/* Initialize array to keep track of frequency of dmer within activeSegment */
|
||||
ushort* segmentFreqs = (ushort*)calloc((ulong)1 << (int)parameters.f, sizeof(ushort));
|
||||
nuint tail = FASTCOVER_buildDictionary(&ctx, ctx.freqs, dictBuffer, dictBufferCapacity, coverParams, segmentFreqs);
|
||||
uint nbFinalizeSamples = (uint)(ctx.nbTrainSamples * ctx.accelParams.finalize / 100);
|
||||
nuint dictionarySize = ZDICT_finalizeDictionary(dict, dictBufferCapacity, dict + tail, dictBufferCapacity - tail, samplesBuffer, samplesSizes, nbFinalizeSamples, coverParams.zParams);
|
||||
if (!ERR_isError(dictionarySize))
|
||||
{
|
||||
}
|
||||
ushort* segmentFreqs = (ushort*)calloc(
|
||||
(ulong)1 << (int)parameters.f,
|
||||
sizeof(ushort)
|
||||
);
|
||||
nuint tail = FASTCOVER_buildDictionary(
|
||||
&ctx,
|
||||
ctx.freqs,
|
||||
dictBuffer,
|
||||
dictBufferCapacity,
|
||||
coverParams,
|
||||
segmentFreqs
|
||||
);
|
||||
uint nbFinalizeSamples = (uint)(
|
||||
ctx.nbTrainSamples * ctx.accelParams.finalize / 100
|
||||
);
|
||||
nuint dictionarySize = ZDICT_finalizeDictionary(
|
||||
dict,
|
||||
dictBufferCapacity,
|
||||
dict + tail,
|
||||
dictBufferCapacity - tail,
|
||||
samplesBuffer,
|
||||
samplesSizes,
|
||||
nbFinalizeSamples,
|
||||
coverParams.zParams
|
||||
);
|
||||
if (!ERR_isError(dictionarySize)) { }
|
||||
|
||||
FASTCOVER_ctx_destroy(&ctx);
|
||||
free(segmentFreqs);
|
||||
@@ -451,7 +595,14 @@ namespace ZstdSharp.Unsafe
|
||||
* See ZDICT_trainFromBuffer() for details on failure modes.
|
||||
* Note: ZDICT_optimizeTrainFromBuffer_fastCover() requires about 6 * 2^f bytes of memory for each thread.
|
||||
*/
|
||||
public static nuint ZDICT_optimizeTrainFromBuffer_fastCover(void* dictBuffer, nuint dictBufferCapacity, void* samplesBuffer, nuint* samplesSizes, uint nbSamples, ZDICT_fastCover_params_t* parameters)
|
||||
public static nuint ZDICT_optimizeTrainFromBuffer_fastCover(
|
||||
void* dictBuffer,
|
||||
nuint dictBufferCapacity,
|
||||
void* samplesBuffer,
|
||||
nuint* samplesSizes,
|
||||
uint nbSamples,
|
||||
ZDICT_fastCover_params_t* parameters
|
||||
)
|
||||
{
|
||||
ZDICT_cover_params_t coverParams;
|
||||
FASTCOVER_accel_t accelParams;
|
||||
@@ -520,7 +671,16 @@ namespace ZstdSharp.Unsafe
|
||||
/* Initialize the context for this value of d */
|
||||
FASTCOVER_ctx_t ctx;
|
||||
{
|
||||
nuint initVal = FASTCOVER_ctx_init(&ctx, samplesBuffer, samplesSizes, nbSamples, d, splitPoint, f, accelParams);
|
||||
nuint initVal = FASTCOVER_ctx_init(
|
||||
&ctx,
|
||||
samplesBuffer,
|
||||
samplesSizes,
|
||||
nbSamples,
|
||||
d,
|
||||
splitPoint,
|
||||
f,
|
||||
accelParams
|
||||
);
|
||||
if (ERR_isError(initVal))
|
||||
{
|
||||
COVER_best_destroy(&best);
|
||||
@@ -538,13 +698,17 @@ namespace ZstdSharp.Unsafe
|
||||
for (k = kMinK; k <= kMaxK; k += kStepSize)
|
||||
{
|
||||
/* Prepare the arguments */
|
||||
FASTCOVER_tryParameters_data_s* data = (FASTCOVER_tryParameters_data_s*)malloc((ulong)sizeof(FASTCOVER_tryParameters_data_s));
|
||||
FASTCOVER_tryParameters_data_s* data = (FASTCOVER_tryParameters_data_s*)malloc(
|
||||
(ulong)sizeof(FASTCOVER_tryParameters_data_s)
|
||||
);
|
||||
if (data == null)
|
||||
{
|
||||
COVER_best_destroy(&best);
|
||||
FASTCOVER_ctx_destroy(&ctx);
|
||||
POOL_free(pool);
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)
|
||||
);
|
||||
}
|
||||
|
||||
data->ctx = &ctx;
|
||||
@@ -557,7 +721,14 @@ namespace ZstdSharp.Unsafe
|
||||
data->parameters.steps = kSteps;
|
||||
data->parameters.shrinkDict = shrinkDict;
|
||||
data->parameters.zParams.notificationLevel = (uint)g_displayLevel;
|
||||
if (FASTCOVER_checkParameters(data->parameters, dictBufferCapacity, data->ctx->f, accel) == 0)
|
||||
if (
|
||||
FASTCOVER_checkParameters(
|
||||
data->parameters,
|
||||
dictBufferCapacity,
|
||||
data->ctx->f,
|
||||
accel
|
||||
) == 0
|
||||
)
|
||||
{
|
||||
free(data);
|
||||
continue;
|
||||
@@ -566,7 +737,11 @@ namespace ZstdSharp.Unsafe
|
||||
COVER_best_start(&best);
|
||||
if (pool != null)
|
||||
{
|
||||
POOL_add(pool, (delegate* managed<void*, void>)(&FASTCOVER_tryParameters), data);
|
||||
POOL_add(
|
||||
pool,
|
||||
(delegate* managed<void*, void>)(&FASTCOVER_tryParameters),
|
||||
data
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -598,4 +773,4 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace ZstdSharp.Unsafe
|
||||
public fixed uint events[1024];
|
||||
public nuint nbEvents;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,28 +25,52 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
FSE_initCState(ref statePtr, ct);
|
||||
{
|
||||
FSE_symbolCompressionTransform symbolTT = ((FSE_symbolCompressionTransform*)statePtr.symbolTT)[symbol];
|
||||
FSE_symbolCompressionTransform symbolTT = (
|
||||
(FSE_symbolCompressionTransform*)statePtr.symbolTT
|
||||
)[symbol];
|
||||
ushort* stateTable = (ushort*)statePtr.stateTable;
|
||||
uint nbBitsOut = symbolTT.deltaNbBits + (1 << 15) >> 16;
|
||||
statePtr.value = (nint)((nbBitsOut << 16) - symbolTT.deltaNbBits);
|
||||
statePtr.value = stateTable[(statePtr.value >> (int)nbBitsOut) + symbolTT.deltaFindState];
|
||||
statePtr.value = stateTable[
|
||||
(statePtr.value >> (int)nbBitsOut) + symbolTT.deltaFindState
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void FSE_encodeSymbol(ref nuint bitC_bitContainer, ref uint bitC_bitPos, ref FSE_CState_t statePtr, uint symbol)
|
||||
private static void FSE_encodeSymbol(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
ref FSE_CState_t statePtr,
|
||||
uint symbol
|
||||
)
|
||||
{
|
||||
FSE_symbolCompressionTransform symbolTT = ((FSE_symbolCompressionTransform*)statePtr.symbolTT)[symbol];
|
||||
FSE_symbolCompressionTransform symbolTT = (
|
||||
(FSE_symbolCompressionTransform*)statePtr.symbolTT
|
||||
)[symbol];
|
||||
ushort* stateTable = (ushort*)statePtr.stateTable;
|
||||
uint nbBitsOut = (uint)statePtr.value + symbolTT.deltaNbBits >> 16;
|
||||
BIT_addBits(ref bitC_bitContainer, ref bitC_bitPos, (nuint)statePtr.value, nbBitsOut);
|
||||
statePtr.value = stateTable[(statePtr.value >> (int)nbBitsOut) + symbolTT.deltaFindState];
|
||||
statePtr.value = stateTable[
|
||||
(statePtr.value >> (int)nbBitsOut) + symbolTT.deltaFindState
|
||||
];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void FSE_flushCState(ref nuint bitC_bitContainer, ref uint bitC_bitPos, ref sbyte* bitC_ptr, sbyte* bitC_endPtr, ref FSE_CState_t statePtr)
|
||||
private static void FSE_flushCState(
|
||||
ref nuint bitC_bitContainer,
|
||||
ref uint bitC_bitPos,
|
||||
ref sbyte* bitC_ptr,
|
||||
sbyte* bitC_endPtr,
|
||||
ref FSE_CState_t statePtr
|
||||
)
|
||||
{
|
||||
BIT_addBits(ref bitC_bitContainer, ref bitC_bitPos, (nuint)statePtr.value, statePtr.stateLog);
|
||||
BIT_addBits(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
(nuint)statePtr.value,
|
||||
statePtr.stateLog
|
||||
);
|
||||
BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
}
|
||||
|
||||
@@ -67,7 +91,12 @@ namespace ZstdSharp.Unsafe
|
||||
* note 1 : assume symbolValue is valid (<= maxSymbolValue)
|
||||
* note 2 : if freq[symbolValue]==0, @return a fake cost of tableLog+1 bits */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static uint FSE_bitCost(void* symbolTTPtr, uint tableLog, uint symbolValue, uint accuracyLog)
|
||||
private static uint FSE_bitCost(
|
||||
void* symbolTTPtr,
|
||||
uint tableLog,
|
||||
uint symbolValue,
|
||||
uint accuracyLog
|
||||
)
|
||||
{
|
||||
FSE_symbolCompressionTransform* symbolTT = (FSE_symbolCompressionTransform*)symbolTTPtr;
|
||||
uint minNbBits = symbolTT[symbolValue].deltaNbBits >> 16;
|
||||
@@ -76,9 +105,11 @@ namespace ZstdSharp.Unsafe
|
||||
assert(accuracyLog < 31 - tableLog);
|
||||
{
|
||||
uint tableSize = (uint)(1 << (int)tableLog);
|
||||
uint deltaFromThreshold = threshold - (symbolTT[symbolValue].deltaNbBits + tableSize);
|
||||
uint deltaFromThreshold =
|
||||
threshold - (symbolTT[symbolValue].deltaNbBits + tableSize);
|
||||
/* linear interpolation (very approximate) */
|
||||
uint normalizedDeltaFromThreshold = deltaFromThreshold << (int)accuracyLog >> (int)tableLog;
|
||||
uint normalizedDeltaFromThreshold =
|
||||
deltaFromThreshold << (int)accuracyLog >> (int)tableLog;
|
||||
uint bitMultiplier = (uint)(1 << (int)accuracyLog);
|
||||
assert(symbolTT[symbolValue].deltaNbBits + tableSize <= threshold);
|
||||
assert(normalizedDeltaFromThreshold <= bitMultiplier);
|
||||
@@ -87,12 +118,26 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void FSE_initDState(ref FSE_DState_t DStatePtr, ref BIT_DStream_t bitD, uint* dt)
|
||||
private static void FSE_initDState(
|
||||
ref FSE_DState_t DStatePtr,
|
||||
ref BIT_DStream_t bitD,
|
||||
uint* dt
|
||||
)
|
||||
{
|
||||
void* ptr = dt;
|
||||
FSE_DTableHeader* DTableH = (FSE_DTableHeader*)ptr;
|
||||
DStatePtr.state = BIT_readBits(bitD.bitContainer, ref bitD.bitsConsumed, DTableH->tableLog);
|
||||
BIT_reloadDStream(ref bitD.bitContainer, ref bitD.bitsConsumed, ref bitD.ptr, bitD.start, bitD.limitPtr);
|
||||
DStatePtr.state = BIT_readBits(
|
||||
bitD.bitContainer,
|
||||
ref bitD.bitsConsumed,
|
||||
DTableH->tableLog
|
||||
);
|
||||
BIT_reloadDStream(
|
||||
ref bitD.bitContainer,
|
||||
ref bitD.bitsConsumed,
|
||||
ref bitD.ptr,
|
||||
bitD.start,
|
||||
bitD.limitPtr
|
||||
);
|
||||
DStatePtr.table = dt + 1;
|
||||
}
|
||||
|
||||
@@ -113,7 +158,11 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static byte FSE_decodeSymbol(ref FSE_DState_t DStatePtr, nuint bitD_bitContainer, ref uint bitD_bitsConsumed)
|
||||
private static byte FSE_decodeSymbol(
|
||||
ref FSE_DState_t DStatePtr,
|
||||
nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed
|
||||
)
|
||||
{
|
||||
FSE_decode_t DInfo = ((FSE_decode_t*)DStatePtr.table)[DStatePtr.state];
|
||||
uint nbBits = DInfo.nbBits;
|
||||
@@ -126,7 +175,11 @@ namespace ZstdSharp.Unsafe
|
||||
/*! FSE_decodeSymbolFast() :
|
||||
unsafe, only works if no symbol has a probability > 50% */
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static byte FSE_decodeSymbolFast(ref FSE_DState_t DStatePtr, nuint bitD_bitContainer, ref uint bitD_bitsConsumed)
|
||||
private static byte FSE_decodeSymbolFast(
|
||||
ref FSE_DState_t DStatePtr,
|
||||
nuint bitD_bitContainer,
|
||||
ref uint bitD_bitsConsumed
|
||||
)
|
||||
{
|
||||
FSE_decode_t DInfo = ((FSE_decode_t*)DStatePtr.table)[DStatePtr.state];
|
||||
uint nbBits = DInfo.nbBits;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
|
||||
namespace ZstdSharp.Unsafe
|
||||
{
|
||||
@@ -11,7 +11,14 @@ namespace ZstdSharp.Unsafe
|
||||
* wkspSize should be sized to handle worst case situation, which is `1<<max_tableLog * sizeof(FSE_FUNCTION_TYPE)`
|
||||
* workSpace must also be properly aligned with FSE_FUNCTION_TYPE requirements
|
||||
*/
|
||||
private static nuint FSE_buildCTable_wksp(uint* ct, short* normalizedCounter, uint maxSymbolValue, uint tableLog, void* workSpace, nuint wkspSize)
|
||||
private static nuint FSE_buildCTable_wksp(
|
||||
uint* ct,
|
||||
short* normalizedCounter,
|
||||
uint maxSymbolValue,
|
||||
uint tableLog,
|
||||
void* workSpace,
|
||||
nuint wkspSize
|
||||
)
|
||||
{
|
||||
uint tableSize = (uint)(1 << (int)tableLog);
|
||||
uint tableMask = tableSize - 1;
|
||||
@@ -28,7 +35,14 @@ namespace ZstdSharp.Unsafe
|
||||
byte* tableSymbol = (byte*)(cumul + (maxSV1 + 1));
|
||||
uint highThreshold = tableSize - 1;
|
||||
assert(((nuint)workSpace & 1) == 0);
|
||||
if (sizeof(uint) * ((maxSymbolValue + 2 + (1UL << (int)tableLog)) / 2 + sizeof(ulong) / sizeof(uint)) > wkspSize)
|
||||
if (
|
||||
sizeof(uint)
|
||||
* (
|
||||
(maxSymbolValue + 2 + (1UL << (int)tableLog)) / 2
|
||||
+ sizeof(ulong) / sizeof(uint)
|
||||
)
|
||||
> wkspSize
|
||||
)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_tableLog_tooLarge));
|
||||
tableU16[-2] = (ushort)tableLog;
|
||||
tableU16[-1] = (ushort)maxSymbolValue;
|
||||
@@ -137,7 +151,8 @@ namespace ZstdSharp.Unsafe
|
||||
switch (normalizedCounter[s])
|
||||
{
|
||||
case 0:
|
||||
symbolTT[s].deltaNbBits = (tableLog + 1 << 16) - (uint)(1 << (int)tableLog);
|
||||
symbolTT[s].deltaNbBits =
|
||||
(tableLog + 1 << 16) - (uint)(1 << (int)tableLog);
|
||||
break;
|
||||
case -1:
|
||||
case 1:
|
||||
@@ -148,11 +163,15 @@ namespace ZstdSharp.Unsafe
|
||||
break;
|
||||
default:
|
||||
assert(normalizedCounter[s] > 1);
|
||||
|
||||
{
|
||||
uint maxBitsOut = tableLog - ZSTD_highbit32((uint)normalizedCounter[s] - 1);
|
||||
uint maxBitsOut =
|
||||
tableLog - ZSTD_highbit32((uint)normalizedCounter[s] - 1);
|
||||
uint minStatePlus = (uint)normalizedCounter[s] << (int)maxBitsOut;
|
||||
symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
|
||||
symbolTT[s].deltaFindState = (int)(total - (uint)normalizedCounter[s]);
|
||||
symbolTT[s].deltaFindState = (int)(
|
||||
total - (uint)normalizedCounter[s]
|
||||
);
|
||||
total += (uint)normalizedCounter[s];
|
||||
}
|
||||
|
||||
@@ -173,7 +192,14 @@ namespace ZstdSharp.Unsafe
|
||||
return maxSymbolValue != 0 ? maxHeaderSize : 512;
|
||||
}
|
||||
|
||||
private static nuint FSE_writeNCount_generic(void* header, nuint headerBufferSize, short* normalizedCounter, uint maxSymbolValue, uint tableLog, uint writeIsSafe)
|
||||
private static nuint FSE_writeNCount_generic(
|
||||
void* header,
|
||||
nuint headerBufferSize,
|
||||
short* normalizedCounter,
|
||||
uint maxSymbolValue,
|
||||
uint tableLog,
|
||||
uint writeIsSafe
|
||||
)
|
||||
{
|
||||
byte* ostart = (byte*)header;
|
||||
byte* @out = ostart;
|
||||
@@ -206,7 +232,9 @@ namespace ZstdSharp.Unsafe
|
||||
start += 24;
|
||||
bitStream += 0xFFFFU << bitCount;
|
||||
if (writeIsSafe == 0 && @out > oend - 2)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)
|
||||
);
|
||||
@out[0] = (byte)bitStream;
|
||||
@out[1] = (byte)(bitStream >> 8);
|
||||
@out += 2;
|
||||
@@ -225,7 +253,9 @@ namespace ZstdSharp.Unsafe
|
||||
if (bitCount > 16)
|
||||
{
|
||||
if (writeIsSafe == 0 && @out > oend - 2)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)
|
||||
);
|
||||
@out[0] = (byte)bitStream;
|
||||
@out[1] = (byte)(bitStream >> 8);
|
||||
@out += 2;
|
||||
@@ -282,15 +312,35 @@ namespace ZstdSharp.Unsafe
|
||||
Compactly save 'normalizedCounter' into 'buffer'.
|
||||
@return : size of the compressed table,
|
||||
or an errorCode, which can be tested using FSE_isError(). */
|
||||
private static nuint FSE_writeNCount(void* buffer, nuint bufferSize, short* normalizedCounter, uint maxSymbolValue, uint tableLog)
|
||||
private static nuint FSE_writeNCount(
|
||||
void* buffer,
|
||||
nuint bufferSize,
|
||||
short* normalizedCounter,
|
||||
uint maxSymbolValue,
|
||||
uint tableLog
|
||||
)
|
||||
{
|
||||
if (tableLog > 14 - 2)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_tableLog_tooLarge));
|
||||
if (tableLog < 5)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC));
|
||||
if (bufferSize < FSE_NCountWriteBound(maxSymbolValue, tableLog))
|
||||
return FSE_writeNCount_generic(buffer, bufferSize, normalizedCounter, maxSymbolValue, tableLog, 0);
|
||||
return FSE_writeNCount_generic(buffer, bufferSize, normalizedCounter, maxSymbolValue, tableLog, 1);
|
||||
return FSE_writeNCount_generic(
|
||||
buffer,
|
||||
bufferSize,
|
||||
normalizedCounter,
|
||||
maxSymbolValue,
|
||||
tableLog,
|
||||
0
|
||||
);
|
||||
return FSE_writeNCount_generic(
|
||||
buffer,
|
||||
bufferSize,
|
||||
normalizedCounter,
|
||||
maxSymbolValue,
|
||||
tableLog,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
/* provides the minimum logSize to safely represent a distribution */
|
||||
@@ -306,7 +356,12 @@ namespace ZstdSharp.Unsafe
|
||||
/* *****************************************
|
||||
* FSE advanced API
|
||||
***************************************** */
|
||||
private static uint FSE_optimalTableLog_internal(uint maxTableLog, nuint srcSize, uint maxSymbolValue, uint minus)
|
||||
private static uint FSE_optimalTableLog_internal(
|
||||
uint maxTableLog,
|
||||
nuint srcSize,
|
||||
uint maxSymbolValue,
|
||||
uint minus
|
||||
)
|
||||
{
|
||||
uint maxBitsSrc = ZSTD_highbit32((uint)(srcSize - 1)) - minus;
|
||||
uint tableLog = maxTableLog;
|
||||
@@ -329,14 +384,25 @@ namespace ZstdSharp.Unsafe
|
||||
dynamically downsize 'tableLog' when conditions are met.
|
||||
It saves CPU time, by using smaller tables, while preserving or even improving compression ratio.
|
||||
@return : recommended tableLog (necessarily <= 'maxTableLog') */
|
||||
private static uint FSE_optimalTableLog(uint maxTableLog, nuint srcSize, uint maxSymbolValue)
|
||||
private static uint FSE_optimalTableLog(
|
||||
uint maxTableLog,
|
||||
nuint srcSize,
|
||||
uint maxSymbolValue
|
||||
)
|
||||
{
|
||||
return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 2);
|
||||
}
|
||||
|
||||
/* Secondary normalization method.
|
||||
To be used when primary method fails. */
|
||||
private static nuint FSE_normalizeM2(short* norm, uint tableLog, uint* count, nuint total, uint maxSymbolValue, short lowProbCount)
|
||||
private static nuint FSE_normalizeM2(
|
||||
short* norm,
|
||||
uint tableLog,
|
||||
uint* count,
|
||||
nuint total,
|
||||
uint maxSymbolValue,
|
||||
short lowProbCount
|
||||
)
|
||||
{
|
||||
const short NOT_YET_ASSIGNED = -2;
|
||||
uint s;
|
||||
@@ -397,7 +463,8 @@ namespace ZstdSharp.Unsafe
|
||||
/* all values are pretty poor;
|
||||
probably incompressible data (should have already been detected);
|
||||
find max, then give all remaining points to max */
|
||||
uint maxV = 0, maxC = 0;
|
||||
uint maxV = 0,
|
||||
maxC = 0;
|
||||
for (s = 0; s <= maxSymbolValue; s++)
|
||||
if (count[s] > maxC)
|
||||
{
|
||||
@@ -447,21 +514,18 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
private static ReadOnlySpan<uint> Span_rtbTable => new uint[8]
|
||||
{
|
||||
0,
|
||||
473195,
|
||||
504333,
|
||||
520860,
|
||||
550000,
|
||||
700000,
|
||||
750000,
|
||||
830000
|
||||
};
|
||||
private static uint* rtbTable => (uint*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref MemoryMarshal.GetReference(Span_rtbTable));
|
||||
private static ReadOnlySpan<uint> Span_rtbTable =>
|
||||
new uint[8] { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
|
||||
private static uint* rtbTable =>
|
||||
(uint*)
|
||||
System.Runtime.CompilerServices.Unsafe.AsPointer(
|
||||
ref MemoryMarshal.GetReference(Span_rtbTable)
|
||||
);
|
||||
#else
|
||||
|
||||
private static readonly uint* rtbTable = GetArrayPointer(new uint[8] { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 });
|
||||
private static readonly uint* rtbTable = GetArrayPointer(
|
||||
new uint[8] { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 }
|
||||
);
|
||||
#endif
|
||||
/*! FSE_normalizeCount():
|
||||
normalize counts so that sum(count[]) == Power_of_2 (2^tableLog)
|
||||
@@ -474,7 +538,14 @@ namespace ZstdSharp.Unsafe
|
||||
Otherwise, useLowProbCount=1 is a good default, since the speed difference is small.
|
||||
@return : tableLog,
|
||||
or an errorCode, which can be tested using FSE_isError() */
|
||||
private static nuint FSE_normalizeCount(short* normalizedCounter, uint tableLog, uint* count, nuint total, uint maxSymbolValue, uint useLowProbCount)
|
||||
private static nuint FSE_normalizeCount(
|
||||
short* normalizedCounter,
|
||||
uint tableLog,
|
||||
uint* count,
|
||||
nuint total,
|
||||
uint maxSymbolValue,
|
||||
uint useLowProbCount
|
||||
)
|
||||
{
|
||||
if (tableLog == 0)
|
||||
tableLog = 13 - 2;
|
||||
@@ -516,7 +587,9 @@ namespace ZstdSharp.Unsafe
|
||||
if (proba < 8)
|
||||
{
|
||||
ulong restToBeat = vStep * rtbTable[proba];
|
||||
proba += (short)(count[s] * step - ((ulong)proba << (int)scale) > restToBeat ? 1 : 0);
|
||||
proba += (short)(
|
||||
count[s] * step - ((ulong)proba << (int)scale) > restToBeat ? 1 : 0
|
||||
);
|
||||
}
|
||||
|
||||
if (proba > largestP)
|
||||
@@ -533,7 +606,14 @@ namespace ZstdSharp.Unsafe
|
||||
if (-stillToDistribute >= normalizedCounter[largest] >> 1)
|
||||
{
|
||||
/* corner case, need another normalization method */
|
||||
nuint errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue, lowProbCount);
|
||||
nuint errorCode = FSE_normalizeM2(
|
||||
normalizedCounter,
|
||||
tableLog,
|
||||
count,
|
||||
total,
|
||||
maxSymbolValue,
|
||||
lowProbCount
|
||||
);
|
||||
if (ERR_isError(errorCode))
|
||||
return errorCode;
|
||||
}
|
||||
@@ -560,14 +640,22 @@ namespace ZstdSharp.Unsafe
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static nuint FSE_compress_usingCTable_generic(void* dst, nuint dstSize, void* src, nuint srcSize, uint* ct, uint fast)
|
||||
private static nuint FSE_compress_usingCTable_generic(
|
||||
void* dst,
|
||||
nuint dstSize,
|
||||
void* src,
|
||||
nuint srcSize,
|
||||
uint* ct,
|
||||
uint fast
|
||||
)
|
||||
{
|
||||
byte* istart = (byte*)src;
|
||||
byte* iend = istart + srcSize;
|
||||
byte* ip = iend;
|
||||
BIT_CStream_t bitC;
|
||||
System.Runtime.CompilerServices.Unsafe.SkipInit(out bitC);
|
||||
FSE_CState_t CState1, CState2;
|
||||
FSE_CState_t CState1,
|
||||
CState2;
|
||||
System.Runtime.CompilerServices.Unsafe.SkipInit(out CState1);
|
||||
System.Runtime.CompilerServices.Unsafe.SkipInit(out CState2);
|
||||
if (srcSize <= 2)
|
||||
@@ -588,9 +676,19 @@ namespace ZstdSharp.Unsafe
|
||||
FSE_initCState2(ref CState2, ct, *--ip);
|
||||
FSE_encodeSymbol(ref bitC_bitContainer, ref bitC_bitPos, ref CState1, *--ip);
|
||||
if (fast != 0)
|
||||
BIT_flushBitsFast(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBitsFast(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
else
|
||||
BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBits(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -604,9 +702,19 @@ namespace ZstdSharp.Unsafe
|
||||
FSE_encodeSymbol(ref bitC_bitContainer, ref bitC_bitPos, ref CState2, *--ip);
|
||||
FSE_encodeSymbol(ref bitC_bitContainer, ref bitC_bitPos, ref CState1, *--ip);
|
||||
if (fast != 0)
|
||||
BIT_flushBitsFast(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBitsFast(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
else
|
||||
BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBits(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
}
|
||||
|
||||
while (ip > istart)
|
||||
@@ -614,9 +722,19 @@ namespace ZstdSharp.Unsafe
|
||||
FSE_encodeSymbol(ref bitC_bitContainer, ref bitC_bitPos, ref CState2, *--ip);
|
||||
if (sizeof(nuint) * 8 < (14 - 2) * 2 + 7)
|
||||
if (fast != 0)
|
||||
BIT_flushBitsFast(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBitsFast(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
else
|
||||
BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBits(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
FSE_encodeSymbol(ref bitC_bitContainer, ref bitC_bitPos, ref CState1, *--ip);
|
||||
if (sizeof(nuint) * 8 > (14 - 2) * 4 + 7)
|
||||
{
|
||||
@@ -625,14 +743,42 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
if (fast != 0)
|
||||
BIT_flushBitsFast(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBitsFast(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
else
|
||||
BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr);
|
||||
BIT_flushBits(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr
|
||||
);
|
||||
}
|
||||
|
||||
FSE_flushCState(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr, ref CState2);
|
||||
FSE_flushCState(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr, ref CState1);
|
||||
return BIT_closeCStream(ref bitC_bitContainer, ref bitC_bitPos, bitC_ptr, bitC_endPtr, bitC.startPtr);
|
||||
FSE_flushCState(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr,
|
||||
ref CState2
|
||||
);
|
||||
FSE_flushCState(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
ref bitC_ptr,
|
||||
bitC_endPtr,
|
||||
ref CState1
|
||||
);
|
||||
return BIT_closeCStream(
|
||||
ref bitC_bitContainer,
|
||||
ref bitC_bitPos,
|
||||
bitC_ptr,
|
||||
bitC_endPtr,
|
||||
bitC.startPtr
|
||||
);
|
||||
}
|
||||
|
||||
/*! FSE_compress_usingCTable():
|
||||
@@ -640,7 +786,13 @@ namespace ZstdSharp.Unsafe
|
||||
@return : size of compressed data (<= `dstCapacity`),
|
||||
or 0 if compressed data could not fit into `dst`,
|
||||
or an errorCode, which can be tested using FSE_isError() */
|
||||
private static nuint FSE_compress_usingCTable(void* dst, nuint dstSize, void* src, nuint srcSize, uint* ct)
|
||||
private static nuint FSE_compress_usingCTable(
|
||||
void* dst,
|
||||
nuint dstSize,
|
||||
void* src,
|
||||
nuint srcSize,
|
||||
uint* ct
|
||||
)
|
||||
{
|
||||
uint fast = dstSize >= srcSize + (srcSize >> 7) + 4 + (nuint)sizeof(nuint) ? 1U : 0U;
|
||||
if (fast != 0)
|
||||
@@ -657,4 +809,4 @@ namespace ZstdSharp.Unsafe
|
||||
return 512 + (size + (size >> 7) + 4 + (nuint)sizeof(nuint));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
|
||||
namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public static unsafe partial class Methods
|
||||
{
|
||||
private static nuint FSE_buildDTable_internal(uint* dt, short* normalizedCounter, uint maxSymbolValue, uint tableLog, void* workSpace, nuint wkspSize)
|
||||
private static nuint FSE_buildDTable_internal(
|
||||
uint* dt,
|
||||
short* normalizedCounter,
|
||||
uint maxSymbolValue,
|
||||
uint tableLog,
|
||||
void* workSpace,
|
||||
nuint wkspSize
|
||||
)
|
||||
{
|
||||
/* because *dt is unsigned, 32-bits aligned on 32-bits */
|
||||
void* tdPtr = dt + 1;
|
||||
@@ -94,7 +101,8 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
uint tableMask = tableSize - 1;
|
||||
uint step = (tableSize >> 1) + (tableSize >> 3) + 3;
|
||||
uint s, position = 0;
|
||||
uint s,
|
||||
position = 0;
|
||||
for (s = 0; s < maxSV1; s++)
|
||||
{
|
||||
int i;
|
||||
@@ -118,23 +126,46 @@ namespace ZstdSharp.Unsafe
|
||||
byte symbol = tableDecode[u].symbol;
|
||||
uint nextState = symbolNext[symbol]++;
|
||||
tableDecode[u].nbBits = (byte)(tableLog - ZSTD_highbit32(nextState));
|
||||
tableDecode[u].newState = (ushort)((nextState << tableDecode[u].nbBits) - tableSize);
|
||||
tableDecode[u].newState = (ushort)(
|
||||
(nextState << tableDecode[u].nbBits) - tableSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static nuint FSE_buildDTable_wksp(uint* dt, short* normalizedCounter, uint maxSymbolValue, uint tableLog, void* workSpace, nuint wkspSize)
|
||||
private static nuint FSE_buildDTable_wksp(
|
||||
uint* dt,
|
||||
short* normalizedCounter,
|
||||
uint maxSymbolValue,
|
||||
uint tableLog,
|
||||
void* workSpace,
|
||||
nuint wkspSize
|
||||
)
|
||||
{
|
||||
return FSE_buildDTable_internal(dt, normalizedCounter, maxSymbolValue, tableLog, workSpace, wkspSize);
|
||||
return FSE_buildDTable_internal(
|
||||
dt,
|
||||
normalizedCounter,
|
||||
maxSymbolValue,
|
||||
tableLog,
|
||||
workSpace,
|
||||
wkspSize
|
||||
);
|
||||
}
|
||||
|
||||
/*-*******************************************************
|
||||
* Decompression (Byte symbols)
|
||||
*********************************************************/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint FSE_decompress_usingDTable_generic(void* dst, nuint maxDstSize, void* cSrc, nuint cSrcSize, uint* dt, uint fast)
|
||||
private static nuint FSE_decompress_usingDTable_generic(
|
||||
void* dst,
|
||||
nuint maxDstSize,
|
||||
void* cSrc,
|
||||
nuint cSrcSize,
|
||||
uint* dt,
|
||||
uint fast
|
||||
)
|
||||
{
|
||||
byte* ostart = (byte*)dst;
|
||||
byte* op = ostart;
|
||||
@@ -160,49 +191,144 @@ namespace ZstdSharp.Unsafe
|
||||
sbyte* bitD_ptr = bitD.ptr;
|
||||
sbyte* bitD_start = bitD.start;
|
||||
sbyte* bitD_limitPtr = bitD.limitPtr;
|
||||
if (BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr) == BIT_DStream_status.BIT_DStream_overflow)
|
||||
if (
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
) == BIT_DStream_status.BIT_DStream_overflow
|
||||
)
|
||||
{
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
|
||||
}
|
||||
|
||||
for (; BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr) == BIT_DStream_status.BIT_DStream_unfinished && op < olimit; op += 4)
|
||||
for (
|
||||
;
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
) == BIT_DStream_status.BIT_DStream_unfinished
|
||||
&& op < olimit;
|
||||
op += 4
|
||||
)
|
||||
{
|
||||
op[0] = fast != 0 ? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
op[0] =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed)
|
||||
: FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if ((14 - 2) * 2 + 7 > sizeof(nuint) * 8)
|
||||
BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr);
|
||||
op[1] = fast != 0 ? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
);
|
||||
op[1] =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed)
|
||||
: FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if ((14 - 2) * 4 + 7 > sizeof(nuint) * 8)
|
||||
{
|
||||
if (BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr) > BIT_DStream_status.BIT_DStream_unfinished)
|
||||
if (
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
) > BIT_DStream_status.BIT_DStream_unfinished
|
||||
)
|
||||
{
|
||||
op += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
op[2] = fast != 0 ? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
op[2] =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed)
|
||||
: FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if ((14 - 2) * 2 + 7 > sizeof(nuint) * 8)
|
||||
BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr);
|
||||
op[3] = fast != 0 ? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
);
|
||||
op[3] =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed)
|
||||
: FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (op > omax - 2)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall));
|
||||
*op++ = fast != 0 ? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if (BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr) == BIT_DStream_status.BIT_DStream_overflow)
|
||||
*op++ =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed)
|
||||
: FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if (
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
) == BIT_DStream_status.BIT_DStream_overflow
|
||||
)
|
||||
{
|
||||
*op++ = fast != 0 ? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
*op++ =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(
|
||||
ref state2,
|
||||
bitD_bitContainer,
|
||||
ref bitD_bitsConsumed
|
||||
)
|
||||
: FSE_decodeSymbol(
|
||||
ref state2,
|
||||
bitD_bitContainer,
|
||||
ref bitD_bitsConsumed
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (op > omax - 2)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall));
|
||||
*op++ = fast != 0 ? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if (BIT_reloadDStream(ref bitD_bitContainer, ref bitD_bitsConsumed, ref bitD_ptr, bitD_start, bitD_limitPtr) == BIT_DStream_status.BIT_DStream_overflow)
|
||||
*op++ =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed)
|
||||
: FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
if (
|
||||
BIT_reloadDStream(
|
||||
ref bitD_bitContainer,
|
||||
ref bitD_bitsConsumed,
|
||||
ref bitD_ptr,
|
||||
bitD_start,
|
||||
bitD_limitPtr
|
||||
) == BIT_DStream_status.BIT_DStream_overflow
|
||||
)
|
||||
{
|
||||
*op++ = fast != 0 ? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed) : FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed);
|
||||
*op++ =
|
||||
fast != 0
|
||||
? FSE_decodeSymbolFast(
|
||||
ref state1,
|
||||
bitD_bitContainer,
|
||||
ref bitD_bitsConsumed
|
||||
)
|
||||
: FSE_decodeSymbol(
|
||||
ref state1,
|
||||
bitD_bitContainer,
|
||||
ref bitD_bitsConsumed
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -212,7 +338,16 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint FSE_decompress_wksp_body(void* dst, nuint dstCapacity, void* cSrc, nuint cSrcSize, uint maxLog, void* workSpace, nuint wkspSize, int bmi2)
|
||||
private static nuint FSE_decompress_wksp_body(
|
||||
void* dst,
|
||||
nuint dstCapacity,
|
||||
void* cSrc,
|
||||
nuint cSrcSize,
|
||||
uint maxLog,
|
||||
void* workSpace,
|
||||
nuint wkspSize,
|
||||
int bmi2
|
||||
)
|
||||
{
|
||||
byte* istart = (byte*)cSrc;
|
||||
byte* ip = istart;
|
||||
@@ -224,7 +359,14 @@ namespace ZstdSharp.Unsafe
|
||||
if (wkspSize < (nuint)sizeof(FSE_DecompressWksp))
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC));
|
||||
{
|
||||
nuint NCountLength = FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
|
||||
nuint NCountLength = FSE_readNCount_bmi2(
|
||||
wksp->ncount,
|
||||
&maxSymbolValue,
|
||||
&tableLog,
|
||||
istart,
|
||||
cSrcSize,
|
||||
bmi2
|
||||
);
|
||||
if (ERR_isError(NCountLength))
|
||||
return NCountLength;
|
||||
if (tableLog > maxLog)
|
||||
@@ -234,13 +376,42 @@ namespace ZstdSharp.Unsafe
|
||||
cSrcSize -= NCountLength;
|
||||
}
|
||||
|
||||
if (((ulong)(1 + (1 << (int)tableLog) + 1) + (sizeof(short) * (maxSymbolValue + 1) + (1UL << (int)tableLog) + 8 + sizeof(uint) - 1) / sizeof(uint) + (255 + 1) / 2 + 1) * sizeof(uint) > wkspSize)
|
||||
if (
|
||||
(
|
||||
(ulong)(1 + (1 << (int)tableLog) + 1)
|
||||
+ (
|
||||
sizeof(short) * (maxSymbolValue + 1)
|
||||
+ (1UL << (int)tableLog)
|
||||
+ 8
|
||||
+ sizeof(uint)
|
||||
- 1
|
||||
) / sizeof(uint)
|
||||
+ (255 + 1) / 2
|
||||
+ 1
|
||||
) * sizeof(uint)
|
||||
> wkspSize
|
||||
)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_tableLog_tooLarge));
|
||||
assert((nuint)(sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint)) <= wkspSize);
|
||||
workSpace = (byte*)workSpace + sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint);
|
||||
wkspSize -= (nuint)(sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint));
|
||||
assert(
|
||||
(nuint)(sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint))
|
||||
<= wkspSize
|
||||
);
|
||||
workSpace =
|
||||
(byte*)workSpace
|
||||
+ sizeof(FSE_DecompressWksp)
|
||||
+ (1 + (1 << (int)tableLog)) * sizeof(uint);
|
||||
wkspSize -= (nuint)(
|
||||
sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint)
|
||||
);
|
||||
{
|
||||
nuint _var_err__ = FSE_buildDTable_internal(dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize);
|
||||
nuint _var_err__ = FSE_buildDTable_internal(
|
||||
dtable,
|
||||
wksp->ncount,
|
||||
maxSymbolValue,
|
||||
tableLog,
|
||||
workSpace,
|
||||
wkspSize
|
||||
);
|
||||
if (ERR_isError(_var_err__))
|
||||
return _var_err__;
|
||||
}
|
||||
@@ -250,20 +421,68 @@ namespace ZstdSharp.Unsafe
|
||||
FSE_DTableHeader* DTableH = (FSE_DTableHeader*)ptr;
|
||||
uint fastMode = DTableH->fastMode;
|
||||
if (fastMode != 0)
|
||||
return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 1);
|
||||
return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 0);
|
||||
return FSE_decompress_usingDTable_generic(
|
||||
dst,
|
||||
dstCapacity,
|
||||
ip,
|
||||
cSrcSize,
|
||||
dtable,
|
||||
1
|
||||
);
|
||||
return FSE_decompress_usingDTable_generic(
|
||||
dst,
|
||||
dstCapacity,
|
||||
ip,
|
||||
cSrcSize,
|
||||
dtable,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Avoids the FORCE_INLINE of the _body() function. */
|
||||
private static nuint FSE_decompress_wksp_body_default(void* dst, nuint dstCapacity, void* cSrc, nuint cSrcSize, uint maxLog, void* workSpace, nuint wkspSize)
|
||||
private static nuint FSE_decompress_wksp_body_default(
|
||||
void* dst,
|
||||
nuint dstCapacity,
|
||||
void* cSrc,
|
||||
nuint cSrcSize,
|
||||
uint maxLog,
|
||||
void* workSpace,
|
||||
nuint wkspSize
|
||||
)
|
||||
{
|
||||
return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 0);
|
||||
return FSE_decompress_wksp_body(
|
||||
dst,
|
||||
dstCapacity,
|
||||
cSrc,
|
||||
cSrcSize,
|
||||
maxLog,
|
||||
workSpace,
|
||||
wkspSize,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
private static nuint FSE_decompress_wksp_bmi2(void* dst, nuint dstCapacity, void* cSrc, nuint cSrcSize, uint maxLog, void* workSpace, nuint wkspSize, int bmi2)
|
||||
private static nuint FSE_decompress_wksp_bmi2(
|
||||
void* dst,
|
||||
nuint dstCapacity,
|
||||
void* cSrc,
|
||||
nuint cSrcSize,
|
||||
uint maxLog,
|
||||
void* workSpace,
|
||||
nuint wkspSize,
|
||||
int bmi2
|
||||
)
|
||||
{
|
||||
return FSE_decompress_wksp_body_default(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize);
|
||||
return FSE_decompress_wksp_body_default(
|
||||
dst,
|
||||
dstCapacity,
|
||||
cSrc,
|
||||
cSrcSize,
|
||||
maxLog,
|
||||
workSpace,
|
||||
wkspSize
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ namespace ZstdSharp.Unsafe
|
||||
public enum HIST_checkInput_e
|
||||
{
|
||||
trustInput,
|
||||
checkMaxSymbolValue
|
||||
checkMaxSymbolValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace ZstdSharp.Unsafe
|
||||
public byte* startPtr;
|
||||
public byte* ptr;
|
||||
public byte* endPtr;
|
||||
|
||||
public unsafe struct _bitContainer_e__FixedBuffer
|
||||
{
|
||||
public nuint e0;
|
||||
@@ -19,4 +20,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint e1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace ZstdSharp.Unsafe
|
||||
public byte maxSymbolValue;
|
||||
public fixed byte unused[6];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ namespace ZstdSharp.Unsafe
|
||||
public fixed uint count[13];
|
||||
public fixed short norm[13];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ namespace ZstdSharp.Unsafe
|
||||
public byte nbBits;
|
||||
public byte @byte;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ namespace ZstdSharp.Unsafe
|
||||
public byte nbBits;
|
||||
public byte length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace ZstdSharp.Unsafe
|
||||
public byte* ilowest;
|
||||
public byte* oend;
|
||||
public _iend_e__FixedBuffer iend;
|
||||
|
||||
public unsafe struct _ip_e__FixedBuffer
|
||||
{
|
||||
public byte* e0;
|
||||
@@ -46,4 +47,4 @@ namespace ZstdSharp.Unsafe
|
||||
public byte* e3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ namespace ZstdSharp.Unsafe
|
||||
public fixed byte symbols[256];
|
||||
public fixed byte huffWeight[256];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ZstdSharp.Unsafe
|
||||
public _sortedSymbol_e__FixedBuffer sortedSymbol;
|
||||
public fixed byte weightList[256];
|
||||
public fixed uint calleeWksp[219];
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
[InlineArray(12)]
|
||||
public unsafe struct _rankVal_e__FixedBuffer
|
||||
@@ -304,4 +305,4 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ namespace ZstdSharp.Unsafe
|
||||
public unsafe struct HUF_WriteCTableWksp
|
||||
{
|
||||
public HUF_CompressWeightsWksp wksp;
|
||||
|
||||
/* precomputed conversion table */
|
||||
public fixed byte bitsToWeight[13];
|
||||
public fixed byte huffWeight[255];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public _huffNodeTbl_e__FixedBuffer huffNodeTbl;
|
||||
public _rankPosition_e__FixedBuffer rankPosition;
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
[InlineArray(512)]
|
||||
public unsafe struct _huffNodeTbl_e__FixedBuffer
|
||||
@@ -736,4 +737,4 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace ZstdSharp.Unsafe
|
||||
public fixed uint count[256];
|
||||
public _CTable_e__FixedBuffer CTable;
|
||||
public _wksps_e__Union wksps;
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
[InlineArray(257)]
|
||||
public unsafe struct _CTable_e__FixedBuffer
|
||||
@@ -277,4 +278,4 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,30 +11,35 @@ namespace ZstdSharp.Unsafe
|
||||
* Otherwise: Ignored.
|
||||
*/
|
||||
HUF_flags_bmi2 = 1 << 0,
|
||||
|
||||
/**
|
||||
* If set: Test possible table depths to find the one that produces the smallest header + encoded size.
|
||||
* If unset: Use heuristic to find the table depth.
|
||||
*/
|
||||
HUF_flags_optimalDepth = 1 << 1,
|
||||
|
||||
/**
|
||||
* If set: If the previous table can encode the input, always reuse the previous table.
|
||||
* If unset: If the previous table can encode the input, reuse the previous table if it results in a smaller output.
|
||||
*/
|
||||
HUF_flags_preferRepeat = 1 << 2,
|
||||
|
||||
/**
|
||||
* If set: Sample the input and check if the sample is uncompressible, if it is then don't attempt to compress.
|
||||
* If unset: Always histogram the entire input.
|
||||
*/
|
||||
HUF_flags_suspectUncompressible = 1 << 3,
|
||||
|
||||
/**
|
||||
* If set: Don't use assembly implementations
|
||||
* If unset: Allow using assembly implementations
|
||||
*/
|
||||
HUF_flags_disableAsm = 1 << 4,
|
||||
|
||||
/**
|
||||
* If set: Don't use the fast decoding loop, always use the fallback decoding loop.
|
||||
* If unset: Use the fast decoding loop when possible.
|
||||
*/
|
||||
HUF_flags_disableFast = 1 << 5
|
||||
HUF_flags_disableFast = 1 << 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ namespace ZstdSharp.Unsafe
|
||||
public enum HUF_nbStreams_e
|
||||
{
|
||||
HUF_singleStream,
|
||||
HUF_fourStreams
|
||||
HUF_fourStreams,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/**< Cannot use the previous table */
|
||||
HUF_repeat_none,
|
||||
|
||||
/**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */
|
||||
HUF_repeat_check,
|
||||
|
||||
/**< Can use the previous table and it is assumed to be valid */
|
||||
HUF_repeat_valid
|
||||
HUF_repeat_valid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,12 @@ namespace ZstdSharp.Unsafe
|
||||
* @return : count of the most frequent symbol.
|
||||
* Note this function doesn't produce any error (i.e. it must succeed).
|
||||
*/
|
||||
private static uint HIST_count_simple(uint* count, uint* maxSymbolValuePtr, void* src, nuint srcSize)
|
||||
private static uint HIST_count_simple(
|
||||
uint* count,
|
||||
uint* maxSymbolValuePtr,
|
||||
void* src,
|
||||
nuint srcSize
|
||||
)
|
||||
{
|
||||
byte* ip = (byte*)src;
|
||||
byte* end = ip + srcSize;
|
||||
@@ -71,7 +76,14 @@ namespace ZstdSharp.Unsafe
|
||||
* `workSpace` must be a U32 table of size >= HIST_WKSP_SIZE_U32.
|
||||
* @return : largest histogram frequency,
|
||||
* or an error code (notably when histogram's alphabet is larger than *maxSymbolValuePtr) */
|
||||
private static nuint HIST_count_parallel_wksp(uint* count, uint* maxSymbolValuePtr, void* source, nuint sourceSize, HIST_checkInput_e check, uint* workSpace)
|
||||
private static nuint HIST_count_parallel_wksp(
|
||||
uint* count,
|
||||
uint* maxSymbolValuePtr,
|
||||
void* source,
|
||||
nuint sourceSize,
|
||||
HIST_checkInput_e check,
|
||||
uint* workSpace
|
||||
)
|
||||
{
|
||||
byte* ip = (byte*)source;
|
||||
byte* iend = ip + sourceSize;
|
||||
@@ -145,7 +157,9 @@ namespace ZstdSharp.Unsafe
|
||||
while (Counting1[maxSymbolValue] == 0)
|
||||
maxSymbolValue--;
|
||||
if (check != default && maxSymbolValue > *maxSymbolValuePtr)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxSymbolValue_tooSmall));
|
||||
return unchecked(
|
||||
(nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxSymbolValue_tooSmall)
|
||||
);
|
||||
*maxSymbolValuePtr = maxSymbolValue;
|
||||
memmove(count, Counting1, countSize);
|
||||
}
|
||||
@@ -158,7 +172,14 @@ namespace ZstdSharp.Unsafe
|
||||
* `workSpace` is a writable buffer which must be 4-bytes aligned,
|
||||
* `workSpaceSize` must be >= HIST_WKSP_SIZE
|
||||
*/
|
||||
private static nuint HIST_countFast_wksp(uint* count, uint* maxSymbolValuePtr, void* source, nuint sourceSize, void* workSpace, nuint workSpaceSize)
|
||||
private static nuint HIST_countFast_wksp(
|
||||
uint* count,
|
||||
uint* maxSymbolValuePtr,
|
||||
void* source,
|
||||
nuint sourceSize,
|
||||
void* workSpace,
|
||||
nuint workSpaceSize
|
||||
)
|
||||
{
|
||||
if (sourceSize < 1500)
|
||||
return HIST_count_simple(count, maxSymbolValuePtr, source, sourceSize);
|
||||
@@ -166,29 +187,69 @@ namespace ZstdSharp.Unsafe
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC));
|
||||
if (workSpaceSize < 1024 * sizeof(uint))
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_workSpace_tooSmall));
|
||||
return HIST_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, HIST_checkInput_e.trustInput, (uint*)workSpace);
|
||||
return HIST_count_parallel_wksp(
|
||||
count,
|
||||
maxSymbolValuePtr,
|
||||
source,
|
||||
sourceSize,
|
||||
HIST_checkInput_e.trustInput,
|
||||
(uint*)workSpace
|
||||
);
|
||||
}
|
||||
|
||||
/* HIST_count_wksp() :
|
||||
* Same as HIST_count(), but using an externally provided scratch buffer.
|
||||
* `workSpace` size must be table of >= HIST_WKSP_SIZE_U32 unsigned */
|
||||
private static nuint HIST_count_wksp(uint* count, uint* maxSymbolValuePtr, void* source, nuint sourceSize, void* workSpace, nuint workSpaceSize)
|
||||
private static nuint HIST_count_wksp(
|
||||
uint* count,
|
||||
uint* maxSymbolValuePtr,
|
||||
void* source,
|
||||
nuint sourceSize,
|
||||
void* workSpace,
|
||||
nuint workSpaceSize
|
||||
)
|
||||
{
|
||||
if (((nuint)workSpace & 3) != 0)
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC));
|
||||
if (workSpaceSize < 1024 * sizeof(uint))
|
||||
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_workSpace_tooSmall));
|
||||
if (*maxSymbolValuePtr < 255)
|
||||
return HIST_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, HIST_checkInput_e.checkMaxSymbolValue, (uint*)workSpace);
|
||||
return HIST_count_parallel_wksp(
|
||||
count,
|
||||
maxSymbolValuePtr,
|
||||
source,
|
||||
sourceSize,
|
||||
HIST_checkInput_e.checkMaxSymbolValue,
|
||||
(uint*)workSpace
|
||||
);
|
||||
*maxSymbolValuePtr = 255;
|
||||
return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, workSpace, workSpaceSize);
|
||||
return HIST_countFast_wksp(
|
||||
count,
|
||||
maxSymbolValuePtr,
|
||||
source,
|
||||
sourceSize,
|
||||
workSpace,
|
||||
workSpaceSize
|
||||
);
|
||||
}
|
||||
|
||||
/* fast variant (unsafe : won't check if src contains values beyond count[] limit) */
|
||||
private static nuint HIST_countFast(uint* count, uint* maxSymbolValuePtr, void* source, nuint sourceSize)
|
||||
private static nuint HIST_countFast(
|
||||
uint* count,
|
||||
uint* maxSymbolValuePtr,
|
||||
void* source,
|
||||
nuint sourceSize
|
||||
)
|
||||
{
|
||||
uint* tmpCounters = stackalloc uint[1024];
|
||||
return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, tmpCounters, sizeof(uint) * 1024);
|
||||
return HIST_countFast_wksp(
|
||||
count,
|
||||
maxSymbolValuePtr,
|
||||
source,
|
||||
sourceSize,
|
||||
tmpCounters,
|
||||
sizeof(uint) * 1024
|
||||
);
|
||||
}
|
||||
|
||||
/*! HIST_count():
|
||||
@@ -199,10 +260,22 @@ namespace ZstdSharp.Unsafe
|
||||
* or an error code, which can be tested using HIST_isError().
|
||||
* note : if return == srcSize, there is only one symbol.
|
||||
*/
|
||||
private static nuint HIST_count(uint* count, uint* maxSymbolValuePtr, void* src, nuint srcSize)
|
||||
private static nuint HIST_count(
|
||||
uint* count,
|
||||
uint* maxSymbolValuePtr,
|
||||
void* src,
|
||||
nuint srcSize
|
||||
)
|
||||
{
|
||||
uint* tmpCounters = stackalloc uint[1024];
|
||||
return HIST_count_wksp(count, maxSymbolValuePtr, src, srcSize, tmpCounters, sizeof(uint) * 1024);
|
||||
return HIST_count_wksp(
|
||||
count,
|
||||
maxSymbolValuePtr,
|
||||
src,
|
||||
srcSize,
|
||||
tmpCounters,
|
||||
sizeof(uint) * 1024
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -41,10 +41,12 @@ namespace ZstdSharp.Unsafe
|
||||
private static nuint MEM_readST(void* memPtr) => BclUnsafe.ReadUnaligned<nuint>(memPtr);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void MEM_write16(void* memPtr, ushort value) => BclUnsafe.WriteUnaligned(memPtr, value);
|
||||
private static void MEM_write16(void* memPtr, ushort value) =>
|
||||
BclUnsafe.WriteUnaligned(memPtr, value);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void MEM_write64(void* memPtr, ulong value) => BclUnsafe.WriteUnaligned(memPtr, value);
|
||||
private static void MEM_write64(void* memPtr, ulong value) =>
|
||||
BclUnsafe.WriteUnaligned(memPtr, value);
|
||||
|
||||
/*=== Little endian r/w ===*/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -125,8 +127,8 @@ namespace ZstdSharp.Unsafe
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static nuint ReverseEndiannessNative(nuint val) =>
|
||||
MEM_32bits
|
||||
? BinaryPrimitives.ReverseEndianness((uint) val)
|
||||
: (nuint) BinaryPrimitives.ReverseEndianness(val);
|
||||
? BinaryPrimitives.ReverseEndianness((uint)val)
|
||||
: (nuint)BinaryPrimitives.ReverseEndianness(val);
|
||||
#endif
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace ZstdSharp.Unsafe
|
||||
public ulong hitMask;
|
||||
public ulong primePower;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public void* start;
|
||||
public nuint size;
|
||||
|
||||
public Range(void* start, nuint size)
|
||||
{
|
||||
this.start = start;
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,27 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* The start of the sequences */
|
||||
public rawSeq* seq;
|
||||
|
||||
/* The index in seq where reading stopped. pos <= size. */
|
||||
public nuint pos;
|
||||
|
||||
/* The position within the sequence at seq[pos] where reading
|
||||
stopped. posInSequence <= seq[pos].litLength + seq[pos].matchLength */
|
||||
public nuint posInSequence;
|
||||
|
||||
/* The number of sequences. <= capacity. */
|
||||
public nuint size;
|
||||
|
||||
/* The capacity starting from `seq` pointer */
|
||||
public nuint capacity;
|
||||
public RawSeqStore_t(rawSeq* seq, nuint pos, nuint posInSequence, nuint size, nuint capacity)
|
||||
|
||||
public RawSeqStore_t(
|
||||
rawSeq* seq,
|
||||
nuint pos,
|
||||
nuint posInSequence,
|
||||
nuint size,
|
||||
nuint capacity
|
||||
)
|
||||
{
|
||||
this.seq = seq;
|
||||
this.pos = pos;
|
||||
@@ -22,4 +33,4 @@ namespace ZstdSharp.Unsafe
|
||||
this.capacity = capacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,17 @@ namespace ZstdSharp.Unsafe
|
||||
* sure it doesn't overlap with any pieces still in use.
|
||||
*/
|
||||
public byte* buffer;
|
||||
|
||||
/* The capacity of buffer. */
|
||||
public nuint capacity;
|
||||
|
||||
/* The position of the current inBuff in the round
|
||||
* buffer. Updated past the end if the inBuff once
|
||||
* the inBuff is sent to the worker thread.
|
||||
* pos <= capacity.
|
||||
*/
|
||||
public nuint pos;
|
||||
|
||||
public RoundBuff_t(byte* buffer, nuint capacity, nuint pos)
|
||||
{
|
||||
this.buffer = buffer;
|
||||
@@ -23,4 +26,4 @@ namespace ZstdSharp.Unsafe
|
||||
this.pos = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint seqIndex;
|
||||
public nuint maxSequences;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace ZstdSharp.Unsafe
|
||||
/* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
|
||||
public uint offBase;
|
||||
public ushort litLength;
|
||||
|
||||
/* mlBase == matchLength - MINMATCH */
|
||||
public ushort mlBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ namespace ZstdSharp.Unsafe
|
||||
public unsafe struct SeqStore_t
|
||||
{
|
||||
public SeqDef_s* sequencesStart;
|
||||
|
||||
/* ptr to end of sequences */
|
||||
public SeqDef_s* sequences;
|
||||
public byte* litStart;
|
||||
|
||||
/* ptr to end of literals */
|
||||
public byte* lit;
|
||||
public byte* llCode;
|
||||
@@ -13,12 +15,14 @@ namespace ZstdSharp.Unsafe
|
||||
public byte* ofCode;
|
||||
public nuint maxNbSeq;
|
||||
public nuint maxNbLit;
|
||||
|
||||
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
||||
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
||||
* the existing value of the litLength or matchLength by 0x10000.
|
||||
*/
|
||||
public ZSTD_longLengthType_e longLengthType;
|
||||
|
||||
/* Index of the sequence to apply long length modification to */
|
||||
public uint longLengthPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@ namespace ZstdSharp.Unsafe
|
||||
public ldmState_t ldmState;
|
||||
public XXH64_state_s xxhState;
|
||||
public uint nextJobID;
|
||||
|
||||
/* Protects ldmWindow.
|
||||
* Must be acquired after the main mutex when acquiring both.
|
||||
*/
|
||||
public void* ldmWindowMutex;
|
||||
|
||||
/* Signaled when ldmWindow is updated */
|
||||
public void* ldmWindowCond;
|
||||
|
||||
/* A thread-safe copy of ldmState.window */
|
||||
public ZSTD_window_t ldmWindow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ namespace ZstdSharp.Unsafe
|
||||
set_basic,
|
||||
set_rle,
|
||||
set_compressed,
|
||||
set_repeat
|
||||
set_repeat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* The number of bytes to load from the input. */
|
||||
public nuint toLoad;
|
||||
|
||||
/* Boolean declaring if we must flush because we found a synchronization point. */
|
||||
public int flush;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ namespace ZstdSharp.Unsafe
|
||||
/*!< Hash bytes, big endian */
|
||||
public fixed byte digest[4];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,20 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/*!< Total length hashed, modulo 2^32 */
|
||||
public uint total_len_32;
|
||||
|
||||
/*!< Whether the hash is >= 16 (handles @ref total_len_32 overflow) */
|
||||
public uint large_len;
|
||||
|
||||
/*!< Accumulator lanes */
|
||||
public fixed uint v[4];
|
||||
|
||||
/*!< Internal buffer for partial reads. Treated as unsigned char[16]. */
|
||||
public fixed uint mem32[4];
|
||||
|
||||
/*!< Amount of data in @ref mem32 */
|
||||
public uint memsize;
|
||||
|
||||
/*!< Reserved field. Do not read nor write to it. */
|
||||
public uint reserved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public fixed byte digest[8];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,20 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/*!< Total length hashed. This is always 64-bit. */
|
||||
public ulong total_len;
|
||||
|
||||
/*!< Accumulator lanes */
|
||||
public fixed ulong v[4];
|
||||
|
||||
/*!< Internal buffer for partial reads. Treated as unsigned char[32]. */
|
||||
public fixed ulong mem64[4];
|
||||
|
||||
/*!< Amount of data in @ref mem64 */
|
||||
public uint memsize;
|
||||
|
||||
/*!< Reserved field, needed for padding anyways*/
|
||||
public uint reserved32;
|
||||
|
||||
/*!< Reserved field. Do not read or write to it. */
|
||||
public ulong reserved64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/*!< Aligned */
|
||||
XXH_aligned,
|
||||
|
||||
/*!< Possibly unaligned */
|
||||
XXH_unaligned
|
||||
XXH_unaligned,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/*!< OK */
|
||||
XXH_OK = 0,
|
||||
|
||||
/*!< Error */
|
||||
XXH_ERROR
|
||||
XXH_ERROR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static ZstdSharp.UnsafeHelper;
|
||||
|
||||
namespace ZstdSharp.Unsafe
|
||||
{
|
||||
@@ -39,13 +39,17 @@ namespace ZstdSharp.Unsafe
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static uint XXH_readLE32(void* ptr)
|
||||
{
|
||||
return BitConverter.IsLittleEndian ? MEM_read32(ptr) : BinaryPrimitives.ReverseEndianness(MEM_read32(ptr));
|
||||
return BitConverter.IsLittleEndian
|
||||
? MEM_read32(ptr)
|
||||
: BinaryPrimitives.ReverseEndianness(MEM_read32(ptr));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static uint XXH_readBE32(void* ptr)
|
||||
{
|
||||
return BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(MEM_read32(ptr)) : MEM_read32(ptr);
|
||||
return BitConverter.IsLittleEndian
|
||||
? BinaryPrimitives.ReverseEndianness(MEM_read32(ptr))
|
||||
: MEM_read32(ptr);
|
||||
}
|
||||
|
||||
private static uint XXH_readLE32_align(void* ptr, XXH_alignment align)
|
||||
@@ -56,7 +60,9 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
else
|
||||
{
|
||||
return BitConverter.IsLittleEndian ? *(uint*)ptr : BinaryPrimitives.ReverseEndianness(*(uint*)ptr);
|
||||
return BitConverter.IsLittleEndian
|
||||
? *(uint*)ptr
|
||||
: BinaryPrimitives.ReverseEndianness(*(uint*)ptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +164,12 @@ namespace ZstdSharp.Unsafe
|
||||
* @param align Whether @p input is aligned.
|
||||
* @return The calculated hash.
|
||||
*/
|
||||
private static uint XXH32_endian_align(byte* input, nuint len, uint seed, XXH_alignment align)
|
||||
private static uint XXH32_endian_align(
|
||||
byte* input,
|
||||
nuint len,
|
||||
uint seed,
|
||||
XXH_alignment align
|
||||
)
|
||||
{
|
||||
uint h32;
|
||||
if (len >= 16)
|
||||
@@ -179,9 +190,12 @@ namespace ZstdSharp.Unsafe
|
||||
input += 4;
|
||||
v4 = XXH32_round(v4, XXH_readLE32_align(input, align));
|
||||
input += 4;
|
||||
}
|
||||
while (input < limit);
|
||||
h32 = BitOperations.RotateLeft(v1, 1) + BitOperations.RotateLeft(v2, 7) + BitOperations.RotateLeft(v3, 12) + BitOperations.RotateLeft(v4, 18);
|
||||
} while (input < limit);
|
||||
h32 =
|
||||
BitOperations.RotateLeft(v1, 1)
|
||||
+ BitOperations.RotateLeft(v2, 7)
|
||||
+ BitOperations.RotateLeft(v3, 12)
|
||||
+ BitOperations.RotateLeft(v4, 18);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -279,8 +293,7 @@ namespace ZstdSharp.Unsafe
|
||||
p += 4;
|
||||
state->v[3] = XXH32_round(state->v[3], XXH_readLE32(p));
|
||||
p += 4;
|
||||
}
|
||||
while (p <= limit);
|
||||
} while (p <= limit);
|
||||
}
|
||||
|
||||
if (p < bEnd)
|
||||
@@ -299,7 +312,11 @@ namespace ZstdSharp.Unsafe
|
||||
uint h32;
|
||||
if (state->large_len != 0)
|
||||
{
|
||||
h32 = BitOperations.RotateLeft(state->v[0], 1) + BitOperations.RotateLeft(state->v[1], 7) + BitOperations.RotateLeft(state->v[2], 12) + BitOperations.RotateLeft(state->v[3], 18);
|
||||
h32 =
|
||||
BitOperations.RotateLeft(state->v[0], 1)
|
||||
+ BitOperations.RotateLeft(state->v[1], 7)
|
||||
+ BitOperations.RotateLeft(state->v[2], 12)
|
||||
+ BitOperations.RotateLeft(state->v[3], 18);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -307,7 +324,12 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
h32 += state->total_len_32;
|
||||
return XXH32_finalize(h32, (byte*)state->mem32, state->memsize, XXH_alignment.XXH_aligned);
|
||||
return XXH32_finalize(
|
||||
h32,
|
||||
(byte*)state->mem32,
|
||||
state->memsize,
|
||||
XXH_alignment.XXH_aligned
|
||||
);
|
||||
}
|
||||
|
||||
/*! @ingroup XXH32_family */
|
||||
@@ -328,13 +350,17 @@ namespace ZstdSharp.Unsafe
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static ulong XXH_readLE64(void* ptr)
|
||||
{
|
||||
return BitConverter.IsLittleEndian ? MEM_read64(ptr) : BinaryPrimitives.ReverseEndianness(MEM_read64(ptr));
|
||||
return BitConverter.IsLittleEndian
|
||||
? MEM_read64(ptr)
|
||||
: BinaryPrimitives.ReverseEndianness(MEM_read64(ptr));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static ulong XXH_readBE64(void* ptr)
|
||||
{
|
||||
return BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(MEM_read64(ptr)) : MEM_read64(ptr);
|
||||
return BitConverter.IsLittleEndian
|
||||
? BinaryPrimitives.ReverseEndianness(MEM_read64(ptr))
|
||||
: MEM_read64(ptr);
|
||||
}
|
||||
|
||||
private static ulong XXH_readLE64_align(void* ptr, XXH_alignment align)
|
||||
@@ -342,7 +368,9 @@ namespace ZstdSharp.Unsafe
|
||||
if (align == XXH_alignment.XXH_unaligned)
|
||||
return XXH_readLE64(ptr);
|
||||
else
|
||||
return BitConverter.IsLittleEndian ? *(ulong*)ptr : BinaryPrimitives.ReverseEndianness(*(ulong*)ptr);
|
||||
return BitConverter.IsLittleEndian
|
||||
? *(ulong*)ptr
|
||||
: BinaryPrimitives.ReverseEndianness(*(ulong*)ptr);
|
||||
}
|
||||
|
||||
/*! @copydoc XXH32_round */
|
||||
@@ -398,7 +426,9 @@ namespace ZstdSharp.Unsafe
|
||||
ulong k1 = XXH64_round(0, XXH_readLE64_align(ptr, align));
|
||||
ptr += 8;
|
||||
hash ^= k1;
|
||||
hash = BitOperations.RotateLeft(hash, 27) * 0x9E3779B185EBCA87UL + 0x85EBCA77C2B2AE63UL;
|
||||
hash =
|
||||
BitOperations.RotateLeft(hash, 27) * 0x9E3779B185EBCA87UL
|
||||
+ 0x85EBCA77C2B2AE63UL;
|
||||
len -= 8;
|
||||
}
|
||||
|
||||
@@ -406,7 +436,9 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
hash ^= XXH_readLE32_align(ptr, align) * 0x9E3779B185EBCA87UL;
|
||||
ptr += 4;
|
||||
hash = BitOperations.RotateLeft(hash, 23) * 0xC2B2AE3D27D4EB4FUL + 0x165667B19E3779F9UL;
|
||||
hash =
|
||||
BitOperations.RotateLeft(hash, 23) * 0xC2B2AE3D27D4EB4FUL
|
||||
+ 0x165667B19E3779F9UL;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
@@ -428,7 +460,12 @@ namespace ZstdSharp.Unsafe
|
||||
* @param align Whether @p input is aligned.
|
||||
* @return The calculated hash.
|
||||
*/
|
||||
private static ulong XXH64_endian_align(byte* input, nuint len, ulong seed, XXH_alignment align)
|
||||
private static ulong XXH64_endian_align(
|
||||
byte* input,
|
||||
nuint len,
|
||||
ulong seed,
|
||||
XXH_alignment align
|
||||
)
|
||||
{
|
||||
ulong h64;
|
||||
if (len >= 32)
|
||||
@@ -449,9 +486,12 @@ namespace ZstdSharp.Unsafe
|
||||
input += 8;
|
||||
v4 = XXH64_round(v4, XXH_readLE64_align(input, align));
|
||||
input += 8;
|
||||
}
|
||||
while (input < limit);
|
||||
h64 = BitOperations.RotateLeft(v1, 1) + BitOperations.RotateLeft(v2, 7) + BitOperations.RotateLeft(v3, 12) + BitOperations.RotateLeft(v4, 18);
|
||||
} while (input < limit);
|
||||
h64 =
|
||||
BitOperations.RotateLeft(v1, 1)
|
||||
+ BitOperations.RotateLeft(v2, 7)
|
||||
+ BitOperations.RotateLeft(v3, 12)
|
||||
+ BitOperations.RotateLeft(v4, 18);
|
||||
h64 = XXH64_mergeRound(h64, v1);
|
||||
h64 = XXH64_mergeRound(h64, v2);
|
||||
h64 = XXH64_mergeRound(h64, v3);
|
||||
@@ -545,8 +585,7 @@ namespace ZstdSharp.Unsafe
|
||||
p += 8;
|
||||
state->v[3] = XXH64_round(state->v[3], XXH_readLE64(p));
|
||||
p += 8;
|
||||
}
|
||||
while (p <= limit);
|
||||
} while (p <= limit);
|
||||
}
|
||||
|
||||
if (p < bEnd)
|
||||
@@ -565,7 +604,11 @@ namespace ZstdSharp.Unsafe
|
||||
ulong h64;
|
||||
if (state->total_len >= 32)
|
||||
{
|
||||
h64 = BitOperations.RotateLeft(state->v[0], 1) + BitOperations.RotateLeft(state->v[1], 7) + BitOperations.RotateLeft(state->v[2], 12) + BitOperations.RotateLeft(state->v[3], 18);
|
||||
h64 =
|
||||
BitOperations.RotateLeft(state->v[0], 1)
|
||||
+ BitOperations.RotateLeft(state->v[1], 7)
|
||||
+ BitOperations.RotateLeft(state->v[2], 12)
|
||||
+ BitOperations.RotateLeft(state->v[3], 18);
|
||||
h64 = XXH64_mergeRound(h64, state->v[0]);
|
||||
h64 = XXH64_mergeRound(h64, state->v[1]);
|
||||
h64 = XXH64_mergeRound(h64, state->v[2]);
|
||||
@@ -577,7 +620,12 @@ namespace ZstdSharp.Unsafe
|
||||
}
|
||||
|
||||
h64 += state->total_len;
|
||||
return XXH64_finalize(h64, (byte*)state->mem64, (nuint)state->total_len, XXH_alignment.XXH_aligned);
|
||||
return XXH64_finalize(
|
||||
h64,
|
||||
(byte*)state->mem64,
|
||||
(nuint)state->total_len,
|
||||
XXH_alignment.XXH_aligned
|
||||
);
|
||||
}
|
||||
|
||||
/*! @ingroup XXH64_family */
|
||||
|
||||
@@ -8,18 +8,24 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* Segment size : constraint: 0 < k : Reasonable range [16, 2048+] */
|
||||
public uint k;
|
||||
|
||||
/* dmer size : constraint: 0 < d <= k : Reasonable range [6, 16] */
|
||||
public uint d;
|
||||
|
||||
/* Number of steps : Only used for optimization : 0 means default (40) : Higher means more parameters checked */
|
||||
public uint steps;
|
||||
|
||||
/* Number of threads : constraint: 0 < nbThreads : 1 means single-threaded : Only used for optimization : Ignored if ZSTD_MULTITHREAD is not defined */
|
||||
public uint nbThreads;
|
||||
|
||||
/* Percentage of samples used for training: Only used for optimization : the first nbSamples * splitPoint samples will be used to training, the last nbSamples * (1 - splitPoint) samples will be used for testing, 0 means default (1.0), 1.0 when all samples are used for both training and testing */
|
||||
public double splitPoint;
|
||||
|
||||
/* Train dictionaries to shrink in size starting from the minimum size and selects the smallest dictionary that is shrinkDictMaxRegression% worse than the largest dictionary. 0 means no shrinking and 1 means shrinking */
|
||||
public uint shrinkDict;
|
||||
|
||||
/* Sets shrinkDictMaxRegression so that a smaller dictionary can be at worse shrinkDictMaxRegression% worse than the max dict size dictionary. */
|
||||
public uint shrinkDictMaxRegression;
|
||||
public ZDICT_params_t zParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,30 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* Segment size : constraint: 0 < k : Reasonable range [16, 2048+] */
|
||||
public uint k;
|
||||
|
||||
/* dmer size : constraint: 0 < d <= k : Reasonable range [6, 16] */
|
||||
public uint d;
|
||||
|
||||
/* log of size of frequency array : constraint: 0 < f <= 31 : 1 means default(20)*/
|
||||
public uint f;
|
||||
|
||||
/* Number of steps : Only used for optimization : 0 means default (40) : Higher means more parameters checked */
|
||||
public uint steps;
|
||||
|
||||
/* Number of threads : constraint: 0 < nbThreads : 1 means single-threaded : Only used for optimization : Ignored if ZSTD_MULTITHREAD is not defined */
|
||||
public uint nbThreads;
|
||||
|
||||
/* Percentage of samples used for training: Only used for optimization : the first nbSamples * splitPoint samples will be used to training, the last nbSamples * (1 - splitPoint) samples will be used for testing, 0 means default (0.75), 1.0 when all samples are used for both training and testing */
|
||||
public double splitPoint;
|
||||
|
||||
/* Acceleration level: constraint: 0 < accel <= 10, higher means faster and less accurate, 0 means default(1) */
|
||||
public uint accel;
|
||||
|
||||
/* Train dictionaries to shrink in size starting from the minimum size and selects the smallest dictionary that is shrinkDictMaxRegression% worse than the largest dictionary. 0 means no shrinking and 1 means shrinking */
|
||||
public uint shrinkDict;
|
||||
|
||||
/* Sets shrinkDictMaxRegression so that a smaller dictionary can be at worse shrinkDictMaxRegression% worse than the max dict size dictionary. */
|
||||
public uint shrinkDictMaxRegression;
|
||||
public ZDICT_params_t zParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace ZstdSharp.Unsafe
|
||||
public uint selectivityLevel;
|
||||
public ZDICT_params_t zParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/**< optimize for a specific zstd compression level; 0 means default */
|
||||
public int compressionLevel;
|
||||
|
||||
/**< Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
|
||||
public uint notificationLevel;
|
||||
|
||||
/**< force dictID value; 0 means auto mode (32-bits random value)
|
||||
* NOTE: The zstd format reserves some dictionary IDs for future use.
|
||||
* You may use them in private settings, but be warned that they
|
||||
@@ -16,4 +18,4 @@ namespace ZstdSharp.Unsafe
|
||||
*/
|
||||
public uint dictID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ namespace ZstdSharp.Unsafe
|
||||
public ZSTD_customMem cMem;
|
||||
public ZSTD_CCtx_s** cctxs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ZstdSharp.Unsafe
|
||||
public ZSTD_CCtx_params_s @params;
|
||||
public nuint targetSectionSize;
|
||||
public nuint targetPrefixSize;
|
||||
|
||||
/* 1 => one job is already prepared, but pool has shortage of workers. Don't create a new job. */
|
||||
public int jobReady;
|
||||
public InBuff_t inBuff;
|
||||
@@ -29,4 +30,4 @@ namespace ZstdSharp.Unsafe
|
||||
public ZSTD_CDict_s* cdict;
|
||||
public uint providedFactory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ namespace ZstdSharp.Unsafe
|
||||
public ZSTD_customMem cMem;
|
||||
public buffer_s* buffers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,41 +4,59 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
/* SHARED - set0 by mtctx, then modified by worker AND read by mtctx */
|
||||
public nuint consumed;
|
||||
|
||||
/* SHARED - set0 by mtctx, then modified by worker AND read by mtctx, then set0 by mtctx */
|
||||
public nuint cSize;
|
||||
|
||||
/* Thread-safe - used by mtctx and worker */
|
||||
public void* job_mutex;
|
||||
|
||||
/* Thread-safe - used by mtctx and worker */
|
||||
public void* job_cond;
|
||||
|
||||
/* Thread-safe - used by mtctx and (all) workers */
|
||||
public ZSTDMT_CCtxPool* cctxPool;
|
||||
|
||||
/* Thread-safe - used by mtctx and (all) workers */
|
||||
public ZSTDMT_bufferPool_s* bufPool;
|
||||
|
||||
/* Thread-safe - used by mtctx and (all) workers */
|
||||
public ZSTDMT_bufferPool_s* seqPool;
|
||||
|
||||
/* Thread-safe - used by mtctx and (all) workers */
|
||||
public SerialState* serial;
|
||||
|
||||
/* set by worker (or mtctx), then read by worker & mtctx, then modified by mtctx => no barrier */
|
||||
public buffer_s dstBuff;
|
||||
|
||||
/* set by mtctx, then read by worker & mtctx => no barrier */
|
||||
public Range prefix;
|
||||
|
||||
/* set by mtctx, then read by worker & mtctx => no barrier */
|
||||
public Range src;
|
||||
|
||||
/* set by mtctx, then read by worker => no barrier */
|
||||
public uint jobID;
|
||||
|
||||
/* set by mtctx, then read by worker => no barrier */
|
||||
public uint firstJob;
|
||||
|
||||
/* set by mtctx, then read by worker => no barrier */
|
||||
public uint lastJob;
|
||||
|
||||
/* set by mtctx, then read by worker => no barrier */
|
||||
public ZSTD_CCtx_params_s @params;
|
||||
|
||||
/* set by mtctx, then read by worker => no barrier */
|
||||
public ZSTD_CDict_s* cdict;
|
||||
|
||||
/* set by mtctx, then read by worker => no barrier */
|
||||
public ulong fullFrameSize;
|
||||
|
||||
/* used only by mtctx */
|
||||
public nuint dstFlushed;
|
||||
|
||||
/* used only by mtctx */
|
||||
public uint frameChecksumNeeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,11 @@ using System.Runtime.InteropServices;
|
||||
namespace ZstdSharp.Unsafe
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate nuint ZSTD_BlockCompressor_f(ZSTD_MatchState_t* bs, SeqStore_t* seqStore, uint* rep, void* src, nuint srcSize);
|
||||
}
|
||||
public unsafe delegate nuint ZSTD_BlockCompressor_f(
|
||||
ZSTD_MatchState_t* bs,
|
||||
SeqStore_t* seqStore,
|
||||
uint* rep,
|
||||
void* src,
|
||||
nuint srcSize
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ namespace ZstdSharp.Unsafe
|
||||
public fixed short norm[53];
|
||||
public fixed uint wksp[285];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ namespace ZstdSharp.Unsafe
|
||||
public enum ZSTD_BuildSeqStore_e
|
||||
{
|
||||
ZSTDbss_compress,
|
||||
ZSTDbss_noCompress
|
||||
ZSTDbss_noCompress,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,34 +6,43 @@ namespace ZstdSharp.Unsafe
|
||||
public ZSTD_compressionParameters cParams;
|
||||
public ZSTD_frameParameters fParams;
|
||||
public int compressionLevel;
|
||||
|
||||
/* force back-references to respect limit of
|
||||
* 1<<wLog, even for dictionary */
|
||||
public int forceWindow;
|
||||
|
||||
/* Tries to fit compressed block size to be around targetCBlockSize.
|
||||
* No target when targetCBlockSize == 0.
|
||||
* There is no guarantee on compressed block size */
|
||||
public nuint targetCBlockSize;
|
||||
|
||||
/* User's best guess of source size.
|
||||
* Hint is not valid when srcSizeHint == 0.
|
||||
* There is no guarantee that hint is close to actual source size */
|
||||
public int srcSizeHint;
|
||||
public ZSTD_dictAttachPref_e attachDictPref;
|
||||
public ZSTD_paramSwitch_e literalCompressionMode;
|
||||
|
||||
/* Multithreading: used to pass parameters to mtctx */
|
||||
public int nbWorkers;
|
||||
public nuint jobSize;
|
||||
public int overlapLog;
|
||||
public int rsyncable;
|
||||
|
||||
/* Long distance matching parameters */
|
||||
public ldmParams_t ldmParams;
|
||||
|
||||
/* Dedicated dict search algorithm trigger */
|
||||
public int enableDedicatedDictSearch;
|
||||
|
||||
/* Input/output buffer modes */
|
||||
public ZSTD_bufferMode_e inBufferMode;
|
||||
public ZSTD_bufferMode_e outBufferMode;
|
||||
|
||||
/* Sequence compression API */
|
||||
public ZSTD_sequenceFormat_e blockDelimiters;
|
||||
public int validateSequences;
|
||||
|
||||
/* Block splitting
|
||||
* @postBlockSplitter executes split analysis after sequences are produced,
|
||||
* it's more accurate but consumes more resources.
|
||||
@@ -46,25 +55,33 @@ namespace ZstdSharp.Unsafe
|
||||
*/
|
||||
public ZSTD_paramSwitch_e postBlockSplitter;
|
||||
public int preBlockSplitter_level;
|
||||
|
||||
/* Adjust the max block size*/
|
||||
public nuint maxBlockSize;
|
||||
|
||||
/* Param for deciding whether to use row-based matchfinder */
|
||||
public ZSTD_paramSwitch_e useRowMatchFinder;
|
||||
|
||||
/* Always load a dictionary in ext-dict mode (not prefix mode)? */
|
||||
public int deterministicRefPrefix;
|
||||
|
||||
/* Internal use, for createCCtxParams() and freeCCtxParams() only */
|
||||
public ZSTD_customMem customMem;
|
||||
|
||||
/* Controls prefetching in some dictMatchState matchfinders */
|
||||
public ZSTD_paramSwitch_e prefetchCDictTables;
|
||||
|
||||
/* Controls whether zstd will fall back to an internal matchfinder
|
||||
* if the external matchfinder returns an error code. */
|
||||
public int enableMatchFinderFallback;
|
||||
|
||||
/* Parameters for the external sequence producer API.
|
||||
* Users set these parameters through ZSTD_registerSequenceProducer().
|
||||
* It is not possible to set these parameters individually through the public API. */
|
||||
public void* extSeqProdState;
|
||||
public void* extSeqProdFunc;
|
||||
|
||||
/* Controls repcode search in external sequence parsing */
|
||||
public ZSTD_paramSwitch_e searchForExternalRepcodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,24 @@ namespace ZstdSharp.Unsafe
|
||||
public unsafe struct ZSTD_CCtx_s
|
||||
{
|
||||
public ZSTD_compressionStage_e stage;
|
||||
|
||||
/* == 1 if cParams(except wlog) or compression level are changed in requestedParams. Triggers transmission of new params to ZSTDMT (if available) then reset to 0. */
|
||||
public int cParamsChanged;
|
||||
|
||||
/* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
|
||||
public int bmi2;
|
||||
public ZSTD_CCtx_params_s requestedParams;
|
||||
public ZSTD_CCtx_params_s appliedParams;
|
||||
|
||||
/* Param storage used by the simple API - not sticky. Must only be used in top-level simple API functions for storage. */
|
||||
public ZSTD_CCtx_params_s simpleApiParams;
|
||||
public uint dictID;
|
||||
public nuint dictContentSize;
|
||||
|
||||
/* manages buffer for dynamic allocations */
|
||||
public ZSTD_cwksp workspace;
|
||||
public nuint blockSizeMax;
|
||||
|
||||
/* this way, 0 (default) == unknown */
|
||||
public ulong pledgedSrcSizePlusOne;
|
||||
public ulong consumedSrcSize;
|
||||
@@ -27,21 +32,28 @@ namespace ZstdSharp.Unsafe
|
||||
public SeqCollector seqCollector;
|
||||
public int isFirstBlock;
|
||||
public int initialized;
|
||||
|
||||
/* sequences storage ptrs */
|
||||
public SeqStore_t seqStore;
|
||||
|
||||
/* long distance matching state */
|
||||
public ldmState_t ldmState;
|
||||
|
||||
/* Storage for the ldm output sequences */
|
||||
public rawSeq* ldmSequences;
|
||||
public nuint maxNbLdmSequences;
|
||||
|
||||
/* Mutable reference to external sequences */
|
||||
public RawSeqStore_t externSeqStore;
|
||||
public ZSTD_blockState_t blockState;
|
||||
|
||||
/* used as substitute of stack space - must be aligned for S64 type */
|
||||
public void* tmpWorkspace;
|
||||
public nuint tmpWkspSize;
|
||||
|
||||
/* Whether we are streaming or not */
|
||||
public ZSTD_buffered_policy_e bufferedPolicy;
|
||||
|
||||
/* streaming */
|
||||
public sbyte* inBuff;
|
||||
public nuint inBuffSize;
|
||||
@@ -54,21 +66,27 @@ namespace ZstdSharp.Unsafe
|
||||
public nuint outBuffFlushedSize;
|
||||
public ZSTD_cStreamStage streamStage;
|
||||
public uint frameEnded;
|
||||
|
||||
/* Stable in/out buffer verification */
|
||||
public ZSTD_inBuffer_s expectedInBuffer;
|
||||
|
||||
/* nb bytes within stable input buffer that are said to be consumed but are not */
|
||||
public nuint stableIn_notConsumed;
|
||||
public nuint expectedOutBufferSize;
|
||||
|
||||
/* Dictionary */
|
||||
public ZSTD_localDict localDict;
|
||||
public ZSTD_CDict_s* cdict;
|
||||
|
||||
/* single-usage dictionary */
|
||||
public ZSTD_prefixDict_s prefixDict;
|
||||
public ZSTDMT_CCtx_s* mtctx;
|
||||
|
||||
/* Workspace for block splitter */
|
||||
public ZSTD_blockSplitCtx blockSplitCtx;
|
||||
|
||||
/* Buffer for output from external sequence producer */
|
||||
public ZSTD_Sequence* extSeqBuf;
|
||||
public nuint extSeqBufCapacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ namespace ZstdSharp.Unsafe
|
||||
{
|
||||
public void* dictContent;
|
||||
public nuint dictContentSize;
|
||||
|
||||
/* The dictContentType the CDict was created with */
|
||||
public ZSTD_dictContentType_e dictContentType;
|
||||
|
||||
/* entropy workspace of HUF_WORKSPACE_SIZE bytes */
|
||||
public uint* entropyWorkspace;
|
||||
public ZSTD_cwksp workspace;
|
||||
@@ -16,12 +18,14 @@ namespace ZstdSharp.Unsafe
|
||||
public ZSTD_compressedBlockState_t cBlockState;
|
||||
public ZSTD_customMem customMem;
|
||||
public uint dictID;
|
||||
|
||||
/* 0 indicates that advanced API was used to select CDict params */
|
||||
public int compressionLevel;
|
||||
|
||||
/* Indicates whether the CDict was created with params that would use
|
||||
* row-based matchfinder. Unless the cdict is reloaded, we will use
|
||||
* the same greedy/lazy matchfinder at compression time.
|
||||
*/
|
||||
public ZSTD_paramSwitch_e useRowMatchFinder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,24 @@ namespace ZstdSharp.Unsafe
|
||||
* when selecting and adjusting parameters.
|
||||
*/
|
||||
ZSTD_cpm_noAttachDict = 0,
|
||||
|
||||
/* Compression with ZSTD_dictMatchState or ZSTD_dedicatedDictSearch.
|
||||
* In this mode we only take the srcSize into account when selecting
|
||||
* and adjusting parameters.
|
||||
*/
|
||||
ZSTD_cpm_attachDict = 1,
|
||||
|
||||
/* Creating a CDict.
|
||||
* In this mode we take both the source size and the dictionary size
|
||||
* into account when selecting and adjusting the parameters.
|
||||
*/
|
||||
ZSTD_cpm_createCDict = 2,
|
||||
|
||||
/* ZSTD_getCParams, ZSTD_getParams, ZSTD_adjustParams.
|
||||
* We don't know what these parameters are for. We default to the legacy
|
||||
* behavior of taking both the source size and the dict size into account
|
||||
* when selecting and adjusting parameters.
|
||||
*/
|
||||
ZSTD_cpm_unknown = 3
|
||||
ZSTD_cpm_unknown = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user