Added... len... Yes

This commit is contained in:
abux 2026-08-03 22:07:47 +01:00
parent 5ae089628b
commit 3c411f25b9
3 changed files with 30 additions and 6 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {