Clast.Alp
0.2.0
dotnet add package Clast.Alp --version 0.2.0
NuGet\Install-Package Clast.Alp -Version 0.2.0
<PackageReference Include="Clast.Alp" Version="0.2.0" />
<PackageVersion Include="Clast.Alp" Version="0.2.0" />
<PackageReference Include="Clast.Alp" />
paket add Clast.Alp --version 0.2.0
#r "nuget: Clast.Alp, 0.2.0"
#:package Clast.Alp@0.2.0
#addin nuget:?package=Clast.Alp&version=0.2.0
#tool nuget:?package=Clast.Alp&version=0.2.0
Clast.Alp
ALP (Adaptive Lossless floating-Point) compression for .NET. Compresses
arrays of double values into a compact byte representation, using a
multi-stage pipeline that exploits the fact that real-world floating-point
data (prices, sensor readings, scientific measurements) is often decimal
in origin and uses limited precision. Compression is fully lossless.
Part of the clast-project.
How it works
The compression pipeline has four stages:
- ALP encode — search for an
(exponent, factor)pair such thatvalue * 10^(exponent - factor)rounds to a small integer. The search picks the pair that produces the fewest exceptions — values that can't be losslessly recovered. Exceptions are stored verbatim and patched in on decode. - Frame-of-Reference (FOR) — subtract the minimum encoded integer so all deltas are non-negative.
- Bit-pack — write each delta using exactly
ceil(log2(max + 1))bits. - Serialize — emit a 24-byte little-endian header followed by the
packed deltas and any exceptions. The full layout is documented in
src/Alp/AlpCompressor.cs.
Decompression reverses each step.
Based on the ALP algorithm originally published by researchers at CWI Amsterdam.
Usage
using Clast.Alp;
double[] prices = [99.99, 100.01, 42.50, 0.01, 1234.56];
byte[] compressed = AlpCompressor.Compress(prices);
double[] decoded = AlpCompressor.Decompress(compressed);
// decoded.SequenceEqual(prices) == true
For pooled-buffer or pipeline scenarios, an IBufferWriter<byte> overload
avoids the output byte[] allocation:
AlpCompressor.Compress(prices, writer); // any IBufferWriter<byte>
For pre-allocated output buffers, use the Span<double> overload paired
with GetDecompressedLength:
int n = AlpCompressor.GetDecompressedLength(compressed);
double[] buffer = ArrayPool<double>.Shared.Rent(n);
try
{
AlpCompressor.Decompress(compressed, buffer);
// ... consume buffer.AsSpan(0, n) ...
}
finally { ArrayPool<double>.Shared.Return(buffer); }
A few low-level utilities are also public for callers who want to integrate ALP encoding into their own data formats without going through the byte serialization:
AlpEncoder.FindBestFactorExponent(samples)— returns the best(exponent, factor)pair for a sample, without performing the encodingAlpEncoder.EncodeValue(value, exponent, factor)— encode a single double to int64AlpDecoder.DecodeValue(encoded, exponent, factor)— decode a single int64 to double
The encode/FOR/bit-pack pipeline stages and the AlpEncodedData
intermediate form are internal implementation details.
Target frameworks
The library targets net8.0 and netstandard2.0. The netstandard2.0
build supplies polyfills for BitOperations.LeadingZeroCount,
double.IsFinite, and the double overloads of BinaryPrimitives, and
relies on PolySharp for Index / Range / init / required
attribute polyfills.
Project layout
| Folder | Project | Targets |
|---|---|---|
src/Alp/ |
Clast.Alp |
net8.0, netstandard2.0 |
tests/Alp.Tests/ |
xunit test suite | net8.0, net472 |
benchmarks/Alp.Benchmarks/ |
BenchmarkDotNet | net8.0, net472 |
The test and benchmark projects target net472 in addition to net8.0
specifically to exercise the netstandard2.0 build of the library on the
.NET Framework runtime.
Building, testing, benchmarking
dotnet build alp.sln
dotnet test tests/Alp.Tests
dotnet run -c Release --project benchmarks/Alp.Benchmarks
The benchmark project is configured with both a net8.0 and a net472
runtime job, so a single invocation will compare performance across
both runtimes.
License
Apache License, Version 2.0. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Clast.Alp:
| Package | Downloads |
|---|---|
|
EngineeredWood.Parquet
A pure-managed Apache Parquet reader and writer for .NET that speaks Apache Arrow, with predicate pushdown, column statistics, and Bloom filters. Preliminary 0.1.0 — APIs may change before 1.0.0. |
GitHub repositories
This package is not used by any popular GitHub repositories.