blob: 717be3d80cd84c667a58179ac82f0d9bc5017dd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
const std = @import("std");
const stack = @import("stack.zig");
pub const StackStack = struct {
allocator: std.mem.Allocator,
data: std.ArrayList(*stack.Stack),
toss: *stack.Stack,
pub fn deinit(self: *StackStack) void {
for (self.data.items) |s| {
s.deinit();
}
self.data.deinit();
self.allocator.destroy(self);
}
pub fn init(allocator: std.mem.Allocator) !*StackStack {
var ss = try allocator.create(StackStack);
errdefer allocator.destroy(ss);
ss.allocator = allocator;
ss.data = std.ArrayList(*stack.Stack).init(allocator);
errdefer ss.data.deinit();
var s = try ss.data.addOne();
s.* = try stack.Stack.init(allocator);
ss.toss = s.*;
return ss;
}
pub inline fn toss(self: *StackStack) *stack.Stack {
return self.toss;
}
};
test "all" {
std.testing.refAllDecls(@This());
}
|