Added getHandle to slot_map.zig
This commit is contained in:
parent
3c411f25b9
commit
40b5ef05c9
1 changed files with 10 additions and 0 deletions
|
|
@ -207,6 +207,16 @@ pub fn SlotMap(comptime T: type) type {
|
||||||
return self.get(handle) != null;
|
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
|
/// Number of live entries
|
||||||
/// Removed (freed) slots are not counted
|
/// Removed (freed) slots are not counted
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue