# convergent
[](https://github.com/MaloWinrhy/convergent/actions)
[](LICENSE)
Lightweight, composable CRDTs (Conflict-Free Replicated Data Types) for decentralized systems.
CRDTs are data structures that can be replicated across nodes, modified independently, and merged with a **mathematically guaranteed consistent result** — no central coordination required.
## Types
| `GCounter` | Grow-only counter | View counts, event tracking |
| `PNCounter` | Positive-Negative counter | Likes/dislikes, stock levels |
| `LWWRegister` | Last-Writer-Wins register | User profile fields, settings |
| `ORSet` | Observed-Remove set | Shopping carts, tag lists |
## Usage
```toml
[dependencies]
convergent = "0.1"
```
```rust
use convergent::{GCounter, Merge};
let mut node_a = GCounter::new("a");
let mut node_b = GCounter::new("b");
node_a.increment(3);
node_b.increment(5);
node_a.merge(&node_b);
assert_eq!(node_a.value(), 8);
```
## Design
Every type implements the `Merge` trait, which guarantees:
- **Commutative** — `a.merge(b) == b.merge(a)`
- **Associative** — `a.merge(b).merge(c) == a.merge(b.merge(c))`
- **Idempotent** — `a.merge(a) == a`
The `LWWRegister` uses [`hlc_id`](https://github.com/MaloWinrhy/hlc_id) for causally-ordered timestamps, connecting this crate to the broader problem of time in distributed systems.
## Related
- [`hlc_id`](https://github.com/MaloWinrhy/hlc_id) — Hybrid Logical Clock IDs (used by `LWWRegister`)
- [A comprehensive study of CRDTs](https://hal.inria.fr/inria-00555588) — Shapiro et al., 2011
## License
MIT