const std = @import("std"); const value = @import("../value.zig"); const Alloc = std.mem.Allocator; const PairMemPool = std.heap.MemoryPool(value.pair.Pair); const Value = value.Value; const PairPtr = value.pair.PairPtr; const PairPool = @This(); alloc: Alloc, pair_pool: PairMemPool, const default_init_cap = 1024; pub fn init(alloc: Alloc) !PairPool { return initCustom(alloc, default_init_cap); } pub fn initCustom(alloc: Alloc, init_cap: usize) !PairPool { return .{ .alloc = alloc, .pair_pool = try PairMemPool.initCapacity(alloc, init_cap), }; } pub fn cons(self: *PairPool, car: Value, cdr: Value) !PairPtr { var p = try self.pair_pool.create(self.alloc); p.car = car; p.cdr = cdr; return p; }