From 3c411f25b9a60d4633fa283a076a1cc141eb9902 Mon Sep 17 00:00:00 2001 From: abux Date: Mon, 3 Aug 2026 22:07:47 +0100 Subject: [PATCH] Added... len... Yes --- src/fixed_slot_map.zig | 12 ++++++++++-- src/keyed_slot_map.zig | 12 ++++++++++-- src/slot_map.zig | 12 ++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/fixed_slot_map.zig b/src/fixed_slot_map.zig index ed6bbc1..390229f 100644 --- a/src/fixed_slot_map.zig +++ b/src/fixed_slot_map.zig @@ -96,11 +96,11 @@ pub fn FixedSlotMap( /// Skips slots that live on the free list ( `󰮢` tombstones `󰮢` ) /// ---------------------------------------------------- fn nextLive( - len: usize, + n: usize, free_list: []const u32, index: *usize, ) ?usize { - while (index.* < len) : (index.* += 1) { + while (index.* < n) : (index.* += 1) { if (std.mem.indexOfScalar(u32, free_list, @intCast(index.*)) == null) { const i = index.*; index.* += 1; @@ -207,6 +207,14 @@ pub fn FixedSlotMap( return self.get(handle) != null; } + /// ---------------------------------------------------- + /// Number of live entries + /// Removed (freed) slots are not counted + /// ---------------------------------------------------- + pub fn len(self: *Self) usize { + return self.values.items().len - self.free_list.items().len; + } + /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn iterator(self: *Self) Iterator { diff --git a/src/keyed_slot_map.zig b/src/keyed_slot_map.zig index 343e152..a24d81c 100644 --- a/src/keyed_slot_map.zig +++ b/src/keyed_slot_map.zig @@ -116,11 +116,11 @@ pub fn KeyedSlotMap( /// Skips slots that live on the free list ( `󰮢` tombstones `󰮢` rip-bozo 😭 ) /// ---------------------------------------------------- fn nextLive( - len: usize, + n: usize, free_list: []const u32, index: *usize, ) ?usize { - while (index.* < len) : (index.* += 1) { + while (index.* < n) : (index.* += 1) { if (std.mem.indexOfScalar(u32, free_list, @intCast(index.*)) == null) { const i = index.*; index.* += 1; @@ -267,6 +267,14 @@ pub fn KeyedSlotMap( return @intCast(self.lookup.count()); } + /// ---------------------------------------------------- + /// Number of live entries + /// Removed (freed) slots are not counted + /// ---------------------------------------------------- + pub fn len(self: *const Self) usize { + return self.slot_map.values.items.len - self.slot_map.free_list.items.len; + } + /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn iterator(self: *Self) Iterator { diff --git a/src/slot_map.zig b/src/slot_map.zig index f7570e0..b23e972 100644 --- a/src/slot_map.zig +++ b/src/slot_map.zig @@ -90,11 +90,11 @@ pub fn SlotMap(comptime T: type) type { /// Skips slots that live on the free list ( `󰮢` tombstones `󰮢` ) /// ---------------------------------------------------- fn nextLive( - len: usize, + n: usize, free_list: []const u32, index: *usize, ) ?usize { - while (index.* < len) : (index.* += 1) { + while (index.* < n) : (index.* += 1) { if (std.mem.indexOfScalar(u32, free_list, @intCast(index.*)) == null) { const i = index.*; index.* += 1; @@ -207,6 +207,14 @@ pub fn SlotMap(comptime T: type) type { return self.get(handle) != null; } + /// ---------------------------------------------------- + /// Number of live entries + /// Removed (freed) slots are not counted + /// ---------------------------------------------------- + pub fn len(self: *const Self) usize { + return self.values.items.len - self.free_list.items.len; + } + /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn iterator(self: *Self) Iterator {