# sedimentree_core
Core data partitioning scheme for efficient metadata-based synchronization.
> [!WARNING]
> This is an early release preview with an unstable API. Do not use for production at this time.
## Overview
Sedimentree organizes data into hierarchical layers (strata) based on the number of leading zero bytes in content hashes. This enables efficient diffing and synchronization of encrypted data without requiring decryption.
```
Depth 0: ████ ███ ████████ ███ ██ (strict filter → few commits per fragment)
↓ require more leading zero bytes
Depth 1: ████████ ████████ ██████ (looser filter → more commits per fragment)
↓ require more leading zero bytes
Depth 2: ████████████████████████ (loosest filter → most commits per fragment)
```
## Key Concepts
### Blobs and Digests
- **Blob** — Binary content (encrypted or plaintext), content-addressed by BLAKE3 hash
- **Digest\<T\>** — 32-byte BLAKE3 content hash, phantom-typed for safety
### Commits and Fragments
| `LooseCommit` | Individual commit metadata with parent references (not yet rolled into a fragment) |
| `Fragment` | A range of commits at a specific depth, bundled with checkpoint metadata |
| `Sedimentree` | Complete metadata structure for a document |
### Wire-count validation
`LooseCommit::new`, `Fragment::new`, and `Fragment::from_parts` return `Result`.
They enforce the existing wire-format limits: 255 unique parents, 255 unique
boundary IDs, and 65,535 unique 12-byte checkpoints. Full checkpoint IDs are
truncated and deduplicated before validation. Opaque blob bytes are unchanged.
The limits are exported as `loose_commit::MAX_PARENTS` and
`fragment::{MAX_BOUNDARIES, MAX_CHECKPOINTS}`. Errors are
`InvalidLooseCommit::TooManyParents` and
`InvalidFragment::{TooManyBoundaries, TooManyCheckpoints}`, each carrying the
actual normalized count.
### Depth Metric
The `DepthMetric` trait determines how commits are partitioned into layers:
```rust
pub trait DepthMetric {
fn to_depth(&self, id: CommitId) -> Depth;
}
```
Default implementation `CountLeadingZeroBytes` uses the number of leading zero bytes in the commit identifier, giving ~1/256 probability per depth level.
## `no_std` Support
This crate is `#![no_std]` compatible by default. Enable the `std` feature for standard library support.
## License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.