diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-06-29 05:35:54 +0200 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-06-29 05:35:54 +0200 |
| commit | d5259ed20eae38bb4f732d829b927dd54cfac5f5 (patch) | |
| tree | f05b649c24f8b7f16d92a7bf45e8bc38045c91e0 /src/zisp/lib/seg_stack.zig | |
| parent | 2b064f4a5f68e65e7f10abbb00ad7fef2f287463 (diff) | |
Minor cleanup.
Diffstat (limited to 'src/zisp/lib/seg_stack.zig')
| -rw-r--r-- | src/zisp/lib/seg_stack.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/zisp/lib/seg_stack.zig b/src/zisp/lib/seg_stack.zig index 0867892..d2c6aaa 100644 --- a/src/zisp/lib/seg_stack.zig +++ b/src/zisp/lib/seg_stack.zig @@ -5,8 +5,13 @@ const std = @import("std"); const Alloc = std.mem.Allocator; /// Segmented linked list backed stack -pub fn SegStack(T: type, seg_max_bytes: usize) type { - const seg_size: usize = (seg_max_bytes - @sizeOf(usize)) / @sizeOf(T); +pub fn SegStack(T: type, seg_max_bytes: comptime_int) type { + + // Each Node has a pointer (= usize) and the element array; calculate the + // correct segment size (as in element count) based on that. + const seg_size = (seg_max_bytes - @sizeOf(usize)) / @sizeOf(T); + + const IdxType = std.math.IntFittingRange(seg_size); comptime { if (seg_size < 4) { @@ -31,7 +36,7 @@ pub fn SegStack(T: type, seg_max_bytes: usize) type { const Self = @This(); head: *Node, - idx: usize = 0, + idx: IdxType = 0, // To prevent "thrashing" we don't immediately deallocate the current // node when it's emptied but rather save it aside. |
