Added getHandle to slot_map.zig

This commit is contained in:
abux 2026-08-07 12:54:57 +01:00
parent 3c411f25b9
commit 40b5ef05c9

View file

@ -207,6 +207,16 @@ pub fn SlotMap(comptime T: type) type {
return self.get(handle) != null;
}
/// ----------------------------------------------------
/// Current valid handle for an index
/// Returns null if out of range or the slot is freed
/// ----------------------------------------------------
pub fn getHandle(self: *const Self, idx: usize) ?Handle(T) {
if (idx >= self.values.items.len) return null;
if (std.mem.indexOfScalar(u32, self.free_list.items, @intCast(idx)) != null) return null;
return .{ .idx = @intCast(idx), .gen = self.generations.items[idx] };
}
/// ----------------------------------------------------
/// Number of live entries
/// Removed (freed) slots are not counted