mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-08 13:24:07 +08:00
build
This commit is contained in:
@@ -862,9 +862,9 @@ comments: true
|
||||
stack_top: ?*inc.ListNode(T) = null, // 将头节点作为栈顶
|
||||
stk_size: usize = 0, // 栈的长度
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造方法(分配内存+初始化栈)
|
||||
// 构造函数(分配内存+初始化栈)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@@ -874,7 +874,7 @@ comments: true
|
||||
self.stk_size = 0;
|
||||
}
|
||||
|
||||
// 析构方法(释放内存)
|
||||
// 析构函数(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
@@ -917,7 +917,7 @@ comments: true
|
||||
pub fn toArray(self: *Self) ![]T {
|
||||
var node = self.stack_top;
|
||||
var res = try self.mem_allocator.alloc(T, self.size());
|
||||
std.mem.set(T, res, @as(T, 0));
|
||||
@memset(res, @as(T, 0));
|
||||
var i: usize = 0;
|
||||
while (i < res.len) : (i += 1) {
|
||||
res[res.len - i - 1] = node.?.val;
|
||||
|
||||
Reference in New Issue
Block a user