╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
217 218 try map.put(key, .{ .int = value }); 219 }, 220 }, 221 else => @compileError("unsupported upsert field type: " ++ @typeName(Field)), 222 } 223 } 224 225 fn upsertBytes( 226 comptime DB: type, 227 comptime hash_kind: hash.HashKind, 228 map: DB.HashMap(.read_write), 229 key: hash.HashInt(hash_kind), 230 value: []const u8, 231 ) !void { 232 var existing_cursor_maybe = try map.getCursor(key); 233 if (existing_cursor_maybe) |*existing_cursor| { 234 if (try bytesEqual(DB, existing_cursor, value)) { 235 return; 236 } 237 } 238 239 var value_cursor = try map.putCursor(key); 240 var write_buffer: [1024]u8 = undefined; 241 var writer = try value_cursor.writer(&write_buffer); 242 try writer.interface.writeAll(value); 243 try writer.finish(); 244 } 245 246 fn bytesEqual( 247 comptime DB: type, 248 cursor: *DB.Cursor(.read_only), 249 value: []const u8, 250 ) !bool { 251 var read_buffer: [1024]u8 = undefined; 252 var reader = try cursor.reader(&read_buffer); 253 if (reader.size != value.len) { 254 return false; 255 } 256 257 var chunk_buffer: [1024]u8 = undefined; 258 var offset: usize = 0; 259 while (offset < value.len) { 260 const chunk_len = @min(chunk_buffer.len, value.len - offset); 261 try reader.interface.readSliceAll(chunk_buffer[0..chunk_len]); 262 if (!std.mem.eql(u8, chunk_buffer[0..chunk_len], value[offset .. offset + chunk_len])) { 263 return false; 264 } 265 offset += chunk_len; 266 } 267 268 return true; 269 } 270