lib/gpalloc/src/cache/pointer.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2
3 pub fn PointerBin(comptime capacity: u16) type {
4 return struct {
5 count: usize = 0,
6 items: [capacity][*]u8 = undefined,
7
8 const Self = @This();
9
10 pub fn pop(bin: *Self) ?[*]u8 {
11 if (bin.count == 0) return null;
12 bin.count -= 1;
13 return bin.items[bin.count];
14 }
15
16 pub fn push(bin: *Self, ptr: [*]u8, limit: usize) bool {
17 std.debug.assert(limit <= capacity);
18 if (bin.count >= limit) return false;
19 bin.items[bin.count] = ptr;
20 bin.count += 1;
21 return true;
22 }
23 };
24 }
25
26 test {
27 std.testing.refAllDecls(@This());
28 }