Skip to content

Commit

Permalink
Tighten CRDT merge docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pyotrk committed May 25, 2026
1 parent 9b12021 commit 18007e5
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 16 deletions.
3 changes: 1 addition & 2 deletions crdt-lib/src/counter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub fn Counter(comptime T: type) type {

/// Merges `other` into `self` by taking the element-wise max of each replica's count.
///
/// `self` is mutated in place; `other` is consumed by value.
/// Caller must deinit `other` after calling merge.
/// `self` is mutated in place; the caller retains ownership of `other`.
pub fn merge(self: *Self, other: Self, gpa: Allocator) Allocator.Error!void {
var it = other.counters.iterator();
while (it.next()) |entry| {
Expand Down
3 changes: 1 addition & 2 deletions crdt-lib/src/mv_register.zig
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ pub fn MvRegister(T: type) type {
/// Merges `other` into `self`, retaining (value, tag) pairs that are not
/// dominated by any other tag (same replica, higher seq).
///
/// `self` is mutated in place; `other` is consumed by value.
/// Caller must deinit `other` after calling merge.
/// `self` is mutated in place; the caller retains ownership of `other`.
pub fn merge(self: *Self, other: Self, gpa: Allocator) Allocator.Error!void {
if (other.values.items.len == 0) return;

Expand Down
3 changes: 1 addition & 2 deletions crdt-lib/src/or_set.zig
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ pub fn OrSet(T: type) type {
/// Merges `other` into `self` by unioning elements and tombstones,
/// then removing tombstoned tags from the element sets.
///
/// `self` is mutated in place; `other` is consumed by value.
/// Caller must deinit `other` after calling merge.
/// `self` is mutated in place; the caller retains ownership of `other`.
pub fn merge(self: *Self, other: Self, gpa: Allocator) Allocator.Error!void {
// Merge other.elements into self.elements (union of tag sets)
{
Expand Down
3 changes: 1 addition & 2 deletions crdt-lib/src/pn_counter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ pub fn PnCounter(comptime T: type) type {

/// Merges `other` into `self` by merging pos and neg G-Counters independently.
///
/// `self` is mutated in place; `other` is consumed by value.
/// Caller must deinit `other` after calling merge.
/// `self` is mutated in place; the caller retains ownership of `other`.
pub fn merge(self: *Self, other: Self, gpa: Allocator) Allocator.Error!void {
try self.pos.merge(other.pos, gpa);
try self.neg.merge(other.neg, gpa);
Expand Down
3 changes: 1 addition & 2 deletions crdt-lib/src/rga.zig
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ pub fn Rga(comptime T: type) type {
///
/// If the same `Id` exists in both states, removal wins:
/// the merged node is marked removed if either side removed it.
/// `self` is mutated in place; `other` is consumed by value.
/// Caller must deinit `other` after calling merge.
/// `self` is mutated in place; the caller retains ownership of `other`.
pub fn merge(self: *Self, other: Self, gpa: Allocator) Allocator.Error!void {
var it = other.nodes.iterator();
while (it.next()) |entry| {
Expand Down
4 changes: 0 additions & 4 deletions crdt-lib/src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,10 @@ fn expectCrdtEqual(a: *Crdt, b: *Crdt, alloc: Allocator) !void {
std.mem.sort(T, b_vals, {}, lessThan);

try testing.expectEqual(a_vals.len, b_vals.len);
std.debug.print("len good\n", .{});
for (a_vals, b_vals) |av, bv| {
try testing.expectEqual(av.value, bv.value);
std.debug.print("value good\n", .{});
try testing.expectEqual(av.tag.replica, bv.tag.replica);
std.debug.print("replica good\n", .{});
try testing.expectEqual(av.tag.seq, bv.tag.seq);
std.debug.print("seq good\n", .{});
}
},
.rga => {
Expand Down
3 changes: 1 addition & 2 deletions crdt-lib/src/set.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ pub fn Set(T: type) type {

/// Merges `other` into `self` by taking the element-wise union.
///
/// `self` is mutated in place; `other` is consumed by value.
/// Caller must deinit `other` after calling merge.
/// `self` is mutated in place; the caller retains ownership of `other`.
pub fn merge(self: *Self, other: Self, gpa: Allocator) Allocator.Error!void {
var it = other.hashset.keyIterator();
while (it.next()) |k| {
Expand Down

0 comments on commit 18007e5

Please sign in to comment.