LbxyCommonLib.ListCompression
0.0.2
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.5
This package targets .NET Framework 4.5. The package is compatible with this framework or higher.
Suggested Alternatives
Additional Details
This package is no longer maintained. Consider migrating to package LbxyCommonLib.
dotnet add package LbxyCommonLib.ListCompression --version 0.0.2
NuGet\Install-Package LbxyCommonLib.ListCompression -Version 0.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LbxyCommonLib.ListCompression" Version="0.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LbxyCommonLib.ListCompression" Version="0.0.2" />
<PackageReference Include="LbxyCommonLib.ListCompression" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LbxyCommonLib.ListCompression --version 0.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LbxyCommonLib.ListCompression, 0.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LbxyCommonLib.ListCompression@0.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LbxyCommonLib.ListCompression&version=0.0.2
#tool nuget:?package=LbxyCommonLib.ListCompression&version=0.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LbxyCommonLib
跨版本兼容的通用帮助类库,面向 .NET Framework 4.5 与现代 .NET(通过 netstandard2.0)。包含高性能、可扩展的“列表压缩”模块,支持基于 Equals 的比较、默认全局压缩、可定制规则,以及自动累加。
安装
从 NuGet 安装
dotnet add package LbxyCommonLib.ListCompression
从源码构建本地包
dotnet pack -c Release
快速开始
using System.Collections.Generic;
using LbxyCommonLib.ListCompression;
using LbxyCommonLib.ListCompression.Interfaces;
using LbxyCommonLib.Numerics;
public sealed class OrderItem : ISummable<OrderItem>
{
public OrderItem(string sku, double qty) { Sku = sku; Qty = qty; }
public string Sku { get; }
public double Qty { get; }
public double GetSummableValue() => Qty;
public OrderItem WithUpdatedSummableValue(double v) => new OrderItem(Sku, v);
public override bool Equals(object o) => o is OrderItem other && Sku == other.Sku;
public override int GetHashCode() => Sku?.GetHashCode() ?? 0;
}
var input = new List<OrderItem>
{
new("A", 1.0), new("A", 2.0), new("B", 3.0), new("B", 4.0)
}.AsReadOnly();
// 全局压缩(默认,按键汇总,保留首次出现顺序)
var compressedGlobal = ListCompressor<OrderItem>.Compress(input);
// 相邻压缩(仅压缩相邻元素)
var adjacentRule = new CompressionRule<OrderItem> { AdjacentOnly = true };
var compressedAdjacent = ListCompressor<OrderItem>.Compress(input, adjacentRule);
// 数值相等性辅助:相对/绝对误差控制与链式调用
double price = 100.000000001;
double baseline = 100.0;
bool roughlyEqual = price
.EqualsRelatively(baseline, relativeError: 1e-8)
&& price.EqualsAbsolutely(baseline, absoluteError: 1e-10);
自定义压缩规则
var rule = new CompressionRule<MyDto>
{
AreEqual = (a, b) => a.Code == b.Code,
SumSelector = x => x.Count,
UpdateSum = (x, sum) => new MyDto(x.Code, (int)sum),
};
var result = ListCompressor<MyDto>.Compress(list, rule);
设计原则
- O(n) 时间复杂度,O(n) 空间复杂度
- 输入为 IReadOnlyList<T>,返回新 List<T>,不修改原列表
- 同步与异步 API(Task)双模式
- 面向 net45 与 netstandard2.0,使用条件属性保证兼容性
测试与基准
- 单元测试位于
tests/LbxyCommonLib.ListCompression.Tests - 基准测试位于
tests/Benchmarks,使用 BenchmarkDotNet
运行:
dotnet test
dotnet run --project tests/Benchmarks
贡献指南
- 使用最新的 .NET SDK(项目通过
global.json固定了版本) - 开发前请先运行
dotnet test确认当前分支通过 - 提交代码前确保本地通过
dotnet build -c Release与dotnet test -c Release - 提交 Pull Request 时:
- 使用英文或中英文混合的标题简要说明变更
- 在描述中列出关键修改点、潜在破坏性变更与测试情况
- 如为新特性,请视情况更新 README 或 CHANGELOG
许可协议
MIT,见 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 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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 | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 0.0.2 | 163 | 2/21/2026 | |
| 0.0.1 | 122 | 2/21/2026 | |
| 0.0.0-alpha.0 | 88 | 2/21/2026 |
See CHANGELOG.md for detailed release notes.