╭ changed ────╮ │src/event.zig│ ╰─────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────╮ │← previous│ ╰──────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │351 else => @compileError("upsert expects a struct"), │ │352 } │ │353 } │ │354 + │ │355 +fn mergeChangedMapEntries( │ │356 + comptime DB: type, │ │357 + target: DB.HashMap(.read_write), │ │358 + parent: DB.HashMap(.read_only), │ │359 + baseline: DB.HashMap(.read_only), │ │360 + comptime is_top_level: bool, │ │361 +) !void { │ │362 + var parent_iter = try parent.iterator(); │ │363 + while (try parent_iter.next()) |kv_pair_cursor| { │ │364 + const kv_pair = try kv_pair_cursor.readKeyValuePair(); │ │365 │ │366 + const baseline_value_cursor = try baseline.getCursor(kv_pair.hash) orelse { │ │367 + try target.put(kv_pair.hash, .{ .slot = kv_pair.value_cursor.slot() }); │ │368 + continue; │ │369 + }; │ │370 + │ │371 + if (baseline_value_cursor.slot().value == kv_pair.value_cursor.slot().value) { │ │372 + continue; │ │373 + } │ │374 + │ │375 + if (kv_pair.value_cursor.slot().tag != baseline_value_cursor.slot().tag) { │ │376 + return error.UnexpectedTag; │ │377 + } │ │378 + │ │379 + const tag = kv_pair.value_cursor.slot().tag; │ │380 + │ │381 + if (tag == .hash_map) { │ │382 + const target_child_cursor = try target.putCursor(kv_pair.hash); │ │383 + const target_child = try DB.HashMap(.read_write).init(target_child_cursor); │ │384 + const parent_child = try DB.HashMap(.read_only).init(kv_pair.value_cursor); │ │385 + const baseline_child = try DB.HashMap(.read_only).init(baseline_value_cursor); │ │386 + try mergeChangedMapEntries(DB, target_child, parent_child, baseline_child, false);│ │387 + } else if (is_top_level) { │ │388 + continue; │ │389 + } else { │ │390 + try target.put(kv_pair.hash, .{ .slot = kv_pair.value_cursor.slot() }); │ │391 + } │ │392 + } │ │393 +} │ │394 + │ │395 fn upsertField( │ │396 comptime DB: type, │ │397 comptime hash_kind: hash.HashKind, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯