Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

[简体中文](docs/CHANGELOG.zh-CN.md)

## [4.2.0] - Stable preparation (not published)

- Consolidate the accepted Preview.1–RC.1 implementation: affected-slot updates, bounded block labels with AVL fallback, and fixed-width snapshot wire conversion.
- Preserve the 64-function / 14-type API, source compatibility, Handles, ownership, failure semantics, LS1/LKS4SNP1 bytes and strict V3 LK1 migration.
- Upgrade both language editions for dynamic editing, managed ordering, stable one-shot sorting, immutable batch processing and historical workflows; expose paired performance and requested-memory figures with all controls and contrary cases.
- Prepare Stable version strings and deterministic five-member C17 amalgamation assets. No publication date, tag, Release or Latest change is assigned here.
- Reuse the unchanged implementation's Windows/Linux evidence: Full/4.1 median paired elapsed ratios 0.629106/0.640047 overall and 0.197718/0.219173 compare-heavy. Native OM can win update-heavy conditions; endpoint flat history remains faster in its measured lifecycle comparison. No new timing run is claimed.
- See [complete preparation and compatibility record](docs/V4_2_0.md). Historical entries below retain their original stage/publication state.

## [4.2.0-rc.1] - Unreleased candidate

- Reconstruct Full documentation against the frozen candidate, including reproducible comparative evidence.
Expand Down
10 changes: 3 additions & 7 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[简体中文](README.zh-CN.md)

> Current published Full Stable: [v4.1.0](https://github.com/RXY712200/LayerKeySort/releases/tag/v4.1.0). See [4.1.0 memory/performance study and limitations](../docs/V4_1_0.md), [historical Stable record](../docs/V4_STABLE.md) and [freeze](../docs/V4_FREEZE.md).
# Full v4.2.0 benchmark guide

The [4.2 RC evidence](../docs/FULL_RC1_EVIDENCE.md) derives charts and summaries from archived final Preview.3 runs. Keep historical raw data unchanged when regenerating them.
> Measurements below retain historical names; Preview.4 is convergence evidence.
> Stable promotion performs no new tuning. Old provisional names below are historical.
[简体中文](README.zh-CN.md)

With benchmarks enabled, the current build retains `layerkeysort_benchmark` for historical V3/V2 comparisons. CMake links it to `layerkeysort_legacy_bench`, which includes legacy sources and private headers. For current Full comparisons, use the archived RC evidence and its linked replay protocol.
For Full v4.2.0 start with the [current evidence summary](../docs/FULL_RC1_EVIDENCE.md), its complete matched controls, lifecycle wall-time comparisons and Windows/Linux scatter figures. The operational source is unchanged from the measured Preview.3 archive. Reproduction regenerates derived presentation, not timing data. The historical harnesses below retain their own V2/V3/V4 scopes; use the linked protocol for each campaign.

# Historical V3 benchmark harness (3.1.0 source)

Expand Down
7 changes: 2 additions & 5 deletions benchmarks/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# 基准指南
# Full v4.2.0 基准指南

[English](README.md)

当前已发布的 Full Stable 为 [v4.1.0](https://github.com/RXY712200/LayerKeySort/releases/tag/v4.1.0)。参见 [4.1.0 内存与性能研究及限制](../docs/V4_1_0.md)、[历史 Stable 记录](../docs/V4_STABLE.md)和[冻结契约](../docs/V4_FREEZE.md)。
[4.2 RC 证据](../docs/FULL_RC1_EVIDENCE.zh-CN.md)从归档的最终 Preview.3 运行导出图表及汇总。重新生成时保留原始数据。以下旧测量仍用当时的名称,Preview.4 为收敛证据。Stable 发布未另作调优。

当前构建启用基准测试后,仍可使用 `layerkeysort_benchmark` 复现 V3/V2 历史比较。CMake 将该程序链接到 `layerkeysort_legacy_bench`,并使用旧版源码和私有头文件。评估当前 Full 时,请参阅上方的 RC 归档证据及其链接的回放协议。
Full v4.2.0 请先读[当前证据汇总](../docs/FULL_RC1_EVIDENCE.zh-CN.md),其中含完整配对对照、生命周期墙钟比较与 Windows/Linux 散点图。运行源码与受测 Preview.3 归档相同。复现派生展示不等于重新采集计时。以下历史程序各自保留 V2/V3/V4 适用范围;按对应协议复现。

## 历史 V3 基准程序(3.1.0 源码)

Expand Down
11 changes: 3 additions & 8 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

[简体中文](API.zh-CN.md)

Preview.5 froze the V4.0 source contract: 64 functions, 14 public types.
V4.0.0 Stable preserved it unchanged, and the released Full 4.1.0 retains
the frozen API. See [4.1.0 record](V4_1_0.md) and historical [Stable record](V4_STABLE.md).
Include `<layerkeysort.h>` only. [Freeze](V4_FREEZE.md) specifies ownership,
statuses and persistent compatibility; [migration](MIGRATION_V3_V4.md) covers the
major source break. [Full v4.1.0](https://github.com/RXY712200/LayerKeySort/releases/tag/v4.1.0) is the current published Stable. V3.1.0 remains for legacy contracts.
Full v4.2.0 retains the frozen 64-function / 14-type V4 source API, LS1 and LKS4SNP1. Include only `<layerkeysort.h>`. The [freeze](V4_FREEZE.md) defines compatibility; the [complete API guide](IMPLEMENTATION_API_REFERENCE.md) maps every function to source and detailed contracts. [V3 migration](MIGRATION_V3_V4.md) covers the major source break.

## Status / comparator / sort

Expand Down Expand Up @@ -39,6 +34,8 @@ with Base-before-Incoming equality. Batch owns sorted chunks; borrowed views exp
with Batch, merge-all favors earlier chunks and returns independently owned Group.
Empty build still requires comparator; chunk size must be nonzero.

If shared payload mutation invalidates GroupBatch sorted chunks, the application must reconstruct or replace the Batch. Borrowed Batch-owned Group views cannot be independently replaced or destroyed and remain valid only while their Batch lives.

## Snapshots / LS1 / wire / restoration

Capture owns copied namespace/associations; callback span must remain valid through
Expand Down Expand Up @@ -139,5 +136,3 @@ all families. tools/verify_v4_api.py rejects unreviewed signature/layout/name ch

- `lks_sort`
- `lks_status_string`

If shared payload mutation invalidates GroupBatch sorted chunks, the application must reconstruct or replace the Batch. Borrowed Batch-owned Group views cannot be independently replaced or destroyed and remain valid only while their Batch lives.
6 changes: 3 additions & 3 deletions docs/API.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English](API.md)

Preview.5 冻结了 V4.0 源码契约,共 64 个函数和 14 个公开类型。V4.0.0 Stable 与已发布的 Full 4.1.0 均保留了该 API。参见 [4.1.0 记录](V4_1_0.md) 和[历史 Stable 记录](V4_STABLE.md)。只需包含 `<layerkeysort.h>`。[冻结契约](V4_FREEZE.md) 规定所有权、状态及持久兼容性;[迁移指南](MIGRATION_V3_V4.md) 解释主版本源码不兼容。当前已发布 Stable 为 [Full v4.1.0](https://github.com/RXY712200/LayerKeySort/releases/tag/v4.1.0)。V3.1.0 仍可用于旧契约。
Full v4.2.0 保留冻结的 V4 源码 API(64 个函数、14 个公开类型)、LS1 和 LKS4SNP1。只需包含 `<layerkeysort.h>`。[冻结契约](V4_FREEZE.zh-CN.md)定义兼容性;[完整 API 指南](IMPLEMENTATION_API_REFERENCE.zh-CN.md)逐函数映射源码与详细契约。[V3 迁移](MIGRATION_V3_V4.zh-CN.md)说明主版本源码变化。

## 状态、比较器与排序

Expand All @@ -20,6 +20,8 @@ Order 拥有结构并借用非空业务对象。相对位置及端点插入创

Group 拥有平面数组副本并借用对象,不含索引或 Path。稳定构建和独立合并都保留等值顺序,合并时 Base 先于 Incoming。Batch 拥有已排序的分块;借用视图随 Batch 失效。合并所有分块时,较早分块优先,返回独立拥有的 Group。空构建也需要比较器,分块大小必须非零。

GroupBatch 的有序分片若因共享载荷修改而失效,应用必须重建或替换 Batch;借用的 Batch 所有 Group 视图不能单独替换或销毁,且仅在 Batch 仍存活时有效。

## 快照、LS1、线格式与恢复

捕获拥有命名空间和关联数据的副本。回调返回的字节区间必须在紧接其后的复制期间保持有效。历史行可在来源和业务对象销毁后存活。当前性要求来源标记和修改代数匹配;加载的快照没有当前性。LS1 精确的小写十六进制命名空间及序号语法,以及 LKS4SNP1 的显式大端格式,均已冻结。格式化和序列化无分配。文本长度不含 NUL,二进制长度为确切字节数,目标空间不足时保持目标不变。反序列化先完整验证借用的输入,再分配内存。恢复非空快照时必须提供解析回调,库按行序号调用它。回调成功时必须返回非空的借用对象指针,允许多行返回同一指针。解析完所有行后,库才构建使用新句柄的新顺序。失败时输出保持 NULL,临时存储随即释放。调用者继续拥有已解析对象,并负责回调的副作用。严格 LK1 导入保留旧坐标含义,旧实时 API 仍不公开。
Expand Down Expand Up @@ -106,5 +108,3 @@ Group 拥有平面数组副本并借用对象,不含索引或 Path。稳定构

- `lks_sort`
- `lks_status_string`

GroupBatch 的有序分片若因共享载荷修改而失效,应用必须重建或替换 Batch;借用的 Batch 所有 Group 视图不能单独替换或销毁,且仅在 Batch 仍存活时有效。
11 changes: 6 additions & 5 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LayerKeySort V4 separates two problems that earlier versions coupled together:

> **live position is contextual; historical/exported position is immutable.**

The current 4.x model, retained in Full 4.1.0 Stable, is intentionally narrow. LayerKeySort manages order; the
Full v4.2.0 combines dynamic order, stable sorting, batch processing and independent history. The
application owns business identity, item payloads, storage and higher-level domain logic.

## 1. Mutable live order
Expand Down Expand Up @@ -41,7 +41,7 @@ of 32 bytes, while Block size grows by 8 bytes. Handles remain at their stable
separately allocated addresses. Allocation frequency, B64 and AVL algorithms
are unchanged; not every workload is faster.

Current 4.2 candidate comparison first uses local positions within a block, then compares two nonzero block labels directly. When either label is zero, AVL ancestry determines the block order. Attachment bounds label work and can leave an untagged block. Ordinary shifts update affected slots; full location repair is reserved for structural changes. See the [candidate evidence](FULL_RC1_EVIDENCE.md).
Full v4.2.0 comparison first uses local positions within a block, then compares two nonzero block labels directly. When either label is zero, AVL ancestry determines the block order. Attachment bounds label work and can leave an untagged block. Ordinary shifts update affected slots; full location repair is reserved for structural changes. See the [matched performance evidence](FULL_RC1_EVIDENCE.md).

The current B64/minimum-32 block policy is private implementation policy. It is not part
of API, wire or persistence compatibility.
Expand All @@ -64,6 +64,8 @@ documented stable equality precedence.
Neither type reintroduces live Path/Tree state. They are batch utilities, not a second
mutable ordering system.

If shared payload mutation invalidates GroupBatch sorted chunks, the application must reconstruct or replace the Batch. Borrowed Batch-owned Group views cannot be independently replaced or destroyed and remain valid only while their Batch lives.

## 4. Immutable historical representation

`LksSnapshot` captures logical order explicitly.
Expand Down Expand Up @@ -117,6 +119,8 @@ LayerKeySort owns its structural objects and copied snapshot bytes.

Immutable Snapshots support concurrent reads when their lifetime is externally protected. Group pure read/read concurrency additionally requires safe application payload access. Externally synchronize Group reads against merge, capture, destruction and relevant Batch operations, including merge-all activity involving constituent Groups. Mutable live sources require caller serialization. Callback reentry guards and atomic SourceMarker lifetime management are not container locks. See the [complete concurrency contract](IMPLEMENTATION_API_REFERENCE.md).

Group pure reads require protected Group lifetime and safe payload access. Synchronize Group accessors against merge, capture, destruction and Batch merge-all involving constituent Groups. Synchronize GroupBatch accessors against merge-all and destruction. Private non-atomic busy fields are read by Group size/item and Batch size/chunk accessors and written by merge and merge-all; capture accesses Group busy and marker state. Capture guards in snapshot.c and atomic SourceMarker references protect reentry/marker lifetime, not container locking. Immutable Snapshot concurrent reads still require lifetime protection throughout reading.

## 7. Long-term product boundary

The mature project is intended to remain narrow around three responsibilities:
Expand All @@ -134,6 +138,3 @@ Current post-v4 roadmap and active technical debt are tracked in
[Freeze](V4_FREEZE.md) defines the V4.0 compatibility contract.
[4.1.0 record](V4_1_0.md) describes the compatible released optimizations;
[v4.0.0 Stable record](V4_STABLE.md) remains historical release evidence.

If shared payload mutation invalidates GroupBatch sorted chunks, the application must reconstruct or replace the Batch. Borrowed Batch-owned Group views cannot be independently replaced or destroyed and remain valid only while their Batch lives.
Group pure reads require protected Group lifetime and safe payload access. Synchronize Group accessors against merge, capture, destruction and Batch merge-all involving constituent Groups. Synchronize GroupBatch accessors against merge-all and destruction. Private non-atomic busy fields are read by Group size/item and Batch size/chunk accessors and written by merge and merge-all; capture accesses Group busy and marker state. Capture guards in snapshot.c and atomic SourceMarker references protect reentry/marker lifetime, not container locking. Immutable Snapshot concurrent reads still require lifetime protection throughout reading.
11 changes: 6 additions & 5 deletions docs/ARCHITECTURE.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

逐文件执行路径(块和 AVL 维护、快照线格式与恢复、旧格式兼容及相关测试)见[实现导读](IMPLEMENTATION_WALKTHROUGH.zh-CN.md)、[64 个公开 API 的源码映射](IMPLEMENTATION_API_REFERENCE.zh-CN.md)、[私有机制和算法](IMPLEMENTATION_INTERNALS.zh-CN.md)与[复现及打包验证](IMPLEMENTATION_VALIDATION.zh-CN.md)。

V4 区分早期版本中相互耦合的两个问题:**实时位置取决于当前容器,历史和导出位置不可变。** 已发布 Full 4.1.0 延续这一边界。LayerKeySort 负责顺序;业务身份、有效载荷、存储和更高层领域逻辑均由应用负责。
V4 区分早期版本中相互耦合的两个问题:**实时位置取决于当前容器,历史和导出位置不可变。** Full v4.2.0 在这一边界下提供动态顺序、稳定排序、批处理及独立历史。业务身份、有效载荷、存储和更高层领域逻辑均由应用负责。

## 1. 可变实时顺序

`LksOrder` 拥有实时记录,这些记录存放在容量有限的局部块中,块由平衡索引管理。每条记录由不透明的 `LksOrderHandle` 引用。Handle 表示一次存活实例。可排序坐标、持久业务身份、序列化键以及物理块或索引地址属于不同概念。无关插入、删除以及保留记录的移动、分裂、再分配、合并和旋转保持 Handle 有效。删除自身或销毁来源时 Handle 失效。因此,实时修改无需重写整个集合的外部坐标。

Full 4.1.0 将 Order 的 owner 指针移至 Block,由记录共享。实测 x64 记录由 32 字节降至 24 字节,块增加 8 字节。Handle 的独立分配和地址保持不变,分配频率、B64 和 AVL 算法也保持不变;不同负载的耗时变化不同。

当前 4.2 候选先使用块内位置;跨块时直接比较两个非零标签。任一为零时根据 AVL 祖先关系判断顺序。接入块时的标签维护工作有界,块可能保持零标签。普通位移只更新受影响槽位;结构变化才执行完整位置修复。见[候选证据](FULL_RC1_EVIDENCE.zh-CN.md)。B64 和最小 32 的策略属于私有实现,可在保持 API、线格式及持久兼容性的前提下改变。
Full v4.2.0 先使用块内位置;跨块时直接比较两个非零标签。任一为零时根据 AVL 祖先关系判断顺序。接入块时的标签维护工作有界,块可能保持零标签。普通位移只更新受影响槽位;结构变化才执行完整位置修复。见[配对性能证据](FULL_RC1_EVIDENCE.zh-CN.md)。B64 和最小 32 的策略属于私有实现,可在保持 API、线格式及持久兼容性的前提下改变。

## 2. 比较器托管的实时顺序

Expand All @@ -22,6 +22,8 @@ Full 4.1.0 将 Order 的 owner 指针移至 Block,由记录共享。实测 x64

`LksGroup` 是借用对象的平面不可变序列。`LksGroupBatch` 拥有排序后的不可变分块,并可按约定的等值优先规则稳定合并。二者用于批处理,无需重新引入实时 Path 或 Tree。

GroupBatch 的有序分片若因共享载荷修改而失效,应用必须重建或替换 Batch;借用的 Batch 所有 Group 视图不能单独替换或销毁,且仅在 Batch 仍存活时有效。

## 4. 不可变历史表示

`LksSnapshot` 显式捕获逻辑顺序,拥有命名空间副本、累计行结束位置(在实测 x64 上每行元数据由 16 字节降至 8 字节)、应用关联字节副本,以及适用时独立存在的来源标记。实时 Handle、块、对象指针、比较器上下文和过去的来源指针均不保留。
Expand All @@ -44,9 +46,8 @@ V4 主公开头不导出实时 V3 Path、Tree 或 OrderedTree API。内部严格

业务对象、比较器上下文、业务身份和外部存储由应用拥有。结构对象和复制的快照字节由 LayerKeySort 拥有。外部保护生命周期时,不可变 Snapshot 支持并发读取。Group 的纯读/读并发还要求应用载荷访问安全;读取必须与合并、捕获、销毁及相关 Batch 活动(包括涉及其分片 Group 的 merge-all)进行外部同步。可变实时来源须由调用者串行访问。回调重入守卫和原子 SourceMarker 生命周期管理都不是容器锁。详见[完整并发契约](IMPLEMENTATION_API_REFERENCE.zh-CN.md)。

Group 的纯读并发必须保护 Group 生命周期并安全访问载荷;Group 访问器须与合并、捕获、销毁及涉及分片的 Batch merge-all 外部同步。GroupBatch 访问器须与 merge-all 和销毁同步。私有非原子 busy 由 Group 大小/项访问器及 Batch 大小/分片访问器读取,由合并及 merge-all 写入;捕获访问 Group busy 和 marker。snapshot.c 的捕获守卫及原子 SourceMarker 引用只管理重入/标记寿命,不提供容器锁。不可变 Snapshot 并发读仍需保护整个读取期间的寿命。

## 7. 长期产品边界

产品聚焦可变顺序引擎、不可变历史表示和不可变批处理工具。数据库、CRDT 引擎、持久身份注册表和通用应用状态属于其他层。路线与债务见 [Issue #3](https://github.com/RXY712200/LayerKeySort/issues/3)。[冻结契约](V4_FREEZE.md)定义 V4.0 兼容性,[4.1.0 记录](V4_1_0.md)说明已发布优化,[v4.0.0 Stable 记录](V4_STABLE.md)保留历史证据。

GroupBatch 的有序分片若因共享载荷修改而失效,应用必须重建或替换 Batch;借用的 Batch 所有 Group 视图不能单独替换或销毁,且仅在 Batch 仍存活时有效。
Group 的纯读并发必须保护 Group 生命周期并安全访问载荷;Group 访问器须与合并、捕获、销毁及涉及分片的 Batch merge-all 外部同步。GroupBatch 访问器须与 merge-all 和销毁同步。私有非原子 busy 由 Group 大小/项访问器及 Batch 大小/分片访问器读取,由合并及 merge-all 写入;捕获访问 Group busy 和 marker。snapshot.c 的捕获守卫及原子 SourceMarker 引用只管理重入/标记寿命,不提供容器锁。不可变 Snapshot 并发读仍需保护整个读取期间的寿命。
Loading
Loading