From dbb85c8ee16ae27621c475a1bb4e7296763fac41 Mon Sep 17 00:00:00 2001 From: asessa Date: Sun, 22 Feb 2026 19:42:54 +0100 Subject: [PATCH] Update codebase to Zig 0.15.2 - Updated build.zig and build.zig.zon for Zig 0.15.2 compatibility - Updated example/build.zig and example/build.zig.zon - Updated source files to use new Zig 0.15.2 API: - bucket.zig, consts.zig, cursor.zig, db.zig - freelist.zig, gc.zig, node.zig, pretty_table.zig - tests.zig, tx.zig, util.zig --- .gitignore | 2 ++ build.zig | 35 +++++++++++++++++++---------------- build.zig.zon | 5 ++++- example/build.zig | 43 ++++++++++++++++++++++++++----------------- example/build.zig.zon | 7 ++++--- src/bucket.zig | 4 ++-- src/consts.zig | 2 +- src/cursor.zig | 4 ++-- src/db.zig | 12 ++++++------ src/freelist.zig | 28 ++++++++++++++-------------- src/gc.zig | 8 ++++---- src/node.zig | 14 +++++++------- src/pretty_table.zig | 10 +++++----- src/tests.zig | 16 ++++++++-------- src/tx.zig | 4 ++-- src/util.zig | 2 +- 16 files changed, 107 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index f8b4f36..0e13fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ dirty zig-cache zig-out +.zig-cache +boltdb.tmp \ No newline at end of file diff --git a/build.zig b/build.zig index 222bf3f..df7a8cb 100644 --- a/build.zig +++ b/build.zig @@ -15,31 +15,36 @@ pub fn build(b: *std.Build) void { // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - // Create module - _ = b.addModule("boltdb", .{ + // Create module for the library with target and optimize options + const lib_module = b.addModule("boltdb", .{ .root_source_file = b.path("src/namespace.zig"), + .target = target, + .optimize = optimize, }); - const lib = b.addStaticLibrary(.{ + // Create static library using the module + const lib = b.addLibrary(.{ .name = "boltdb-zig", - // In this case the main source file is merely a path, however, in more - // complicated build scripts, this could be a generated file. - .root_source_file = b.path("src/root.zig"), - .target = target, - .optimize = optimize, + .linkage = .static, + .root_module = lib_module, }); // This declares intent for the library to be installed into the standard // location when the user invokes the "install" step (the default step when // running `zig build`). b.installArtifact(lib); - const exe = b.addExecutable(.{ - .name = "boltdb-zig", + // Create module for the executable with target and optimize options + const exe_module = b.addModule("boltdb-zig-exe", .{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); + const exe = b.addExecutable(.{ + .name = "boltdb-zig", + .root_module = exe_module, + }); + // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default // step when running `zig build`). @@ -71,17 +76,15 @@ pub fn build(b: *std.Build) void { // Creates a step for unit testing. This only builds the test executable // but does not run it. const lib_unit_tests = b.addTest(.{ - .root_source_file = b.path("src/root.zig"), - .target = target, - .optimize = optimize, + .name = "lib-tests", + .root_module = lib_module, }); const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const exe_unit_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .name = "exe-tests", + .root_module = exe_module, }); const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); diff --git a/build.zig.zon b/build.zig.zon index c830b5f..09b0187 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "boltdb-zig", + .name = .boltdb_zig, // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. .version = "0.0.0", @@ -8,6 +8,9 @@ // This is currently advisory only; Zig does not yet do anything // with this value. //.minimum_zig_version = "0.11.0", + .minimum_zig_version = "0.15.0", + + .fingerprint = 0xf7570c8463436009, // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. diff --git a/example/build.zig b/example/build.zig index 5ad690b..a3365df 100644 --- a/example/build.zig +++ b/example/build.zig @@ -15,32 +15,45 @@ pub fn build(b: *std.Build) void { // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - const lib = b.addStaticLibrary(.{ - .name = "example", - // In this case the main source file is merely a path, however, in more - // complicated build scripts, this could be a generated file. + // Get the boltdb-zig dependency + const boltdbDep = b.dependency("boltdb-zig", .{ + .target = target, + .optimize = optimize, + }); + const boltdbModule = boltdbDep.module("boltdb"); + + // Create module for the example with target and optimize options + const lib_module = b.addModule("example", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, }); + lib_module.addImport("boltdb", boltdbModule); + // Create static library using the module + const lib = b.addLibrary(.{ + .name = "example", + .linkage = .static, + .root_module = lib_module, + }); // This declares intent for the library to be installed into the standard // location when the user invokes the "install" step (the default step when // running `zig build`). b.installArtifact(lib); - const boltdbDep = b.dependency("boltdb-zig", .{ + + // Create module for the executable with target and optimize options + const exe_module = b.addModule("example-exe", .{ + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); + exe_module.addImport("boltdb", boltdbModule); const exe = b.addExecutable(.{ .name = "example", - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .root_module = exe_module, }); - exe.root_module.addImport("boltdb", boltdbDep.module("boltdb")); // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default // step when running `zig build`). @@ -72,20 +85,16 @@ pub fn build(b: *std.Build) void { // Creates a step for unit testing. This only builds the test executable // but does not run it. const lib_unit_tests = b.addTest(.{ - .root_source_file = b.path("src/root.zig"), - .target = target, - .optimize = optimize, + .name = "lib-tests", + .root_module = lib_module, }); - lib_unit_tests.root_module.addImport("boltdb", boltdbDep.module("boltdb")); const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const exe_unit_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .name = "exe-tests", + .root_module = exe_module, }); - exe_unit_tests.root_module.addImport("boltdb", boltdbDep.module("boltdb")); const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); diff --git a/example/build.zig.zon b/example/build.zig.zon index 99cf357..edda60d 100644 --- a/example/build.zig.zon +++ b/example/build.zig.zon @@ -6,12 +6,14 @@ // // It is redundant to include "zig" in this name because it is already // within the Zig package namespace. - .name = "example", + .name = .example, // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. .version = "0.0.0", + .fingerprint = 0x6eec9b9f51bef188, + // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. @@ -24,8 +26,7 @@ // internet connectivity. .dependencies = .{ .@"boltdb-zig" = .{ - .url = "git+https://github.com/laohanlinux/boltdb-zig.git/?ref=align#3ec605eca6a9f85959f81900542fea59cc3eaef6", - .hash = "122056bd20aba7365380a500c315f4a03aa5ea2134685b11fa7e32e312344c28175c", + .path = "..", }, }, .paths = .{ diff --git a/src/bucket.zig b/src/bucket.zig index ce4c5d9..70b29b2 100644 --- a/src/bucket.zig +++ b/src/bucket.zig @@ -693,7 +693,7 @@ pub const Bucket = struct { var itr = self.buckets.?.iterator(); var arenaAllocator = std.heap.ArenaAllocator.init(self.getAllocator()); defer arenaAllocator.deinit(); - var valueBytes = std.ArrayList(u8).init(arenaAllocator.allocator()); + var valueBytes = std.array_list.Managed(u8).init(arenaAllocator.allocator()); while (itr.next()) |entry| { // std.log.info("\t\tRun at bucket({s}) spill!\t\t", .{entry.key_ptr.*}); // If the child bucket is small enough and it has no child buckets then @@ -729,7 +729,7 @@ pub const Bucket = struct { // Update parent node. var c = self.cursor(); const keyPairRef = c._seek(entry.key_ptr.*); - assert(std.mem.eql(u8, entry.key_ptr.*, keyPairRef.key.?), "misplaced bucket header: {s} -> {s}", .{ std.fmt.fmtSliceHexLower(entry.key_ptr.*), std.fmt.fmtSliceHexLower(keyPairRef.key.?) }); + assert(std.mem.eql(u8, entry.key_ptr.*, keyPairRef.key.?), "misplaced bucket header: {s} -> {s}", .{ entry.key_ptr.*, keyPairRef.key.? }); assert(keyPairRef.flag & consts.BucketLeafFlag != 0, "unexpeced bucket header flag: 0x{x}", .{keyPairRef.flag}); const keyNode = c.node().?; // TODO if the newKey == oldKey, then no need to dupe the key. diff --git a/src/consts.zig b/src/consts.zig index 500c12e..cf41b62 100644 --- a/src/consts.zig +++ b/src/consts.zig @@ -49,7 +49,7 @@ pub const PgidType = u64; /// A slice of page ids. pub const PgIds = []PgidType; /// The size of a page. -pub const PageSize: usize = std.mem.page_size; +pub const PageSize: usize = std.heap.page_size_min; // pub const PageSize: usize = 4096; /// Represents the options that can be set when opening a database. diff --git a/src/cursor.zig b/src/cursor.zig index ad406a0..eb94fb0 100644 --- a/src/cursor.zig +++ b/src/cursor.zig @@ -16,7 +16,7 @@ const Error = @import("error.zig").Error; pub const Cursor = struct { _bucket: *Bucket, - stack: std.ArrayList(ElementRef), + stack: std.array_list.Managed(ElementRef), allocator: std.mem.Allocator, arenaAllocator: ?std.heap.ArenaAllocator, @@ -28,7 +28,7 @@ pub const Cursor = struct { const allocator = _bt.getAllocator(); return Cursor{ ._bucket = _bt, - .stack = std.ArrayList(ElementRef).init(allocator), + .stack = std.array_list.Managed(ElementRef).init(allocator), .allocator = allocator, .arenaAllocator = null, }; diff --git a/src/db.zig b/src/db.zig index d51404c..bdd33ca 100644 --- a/src/db.zig +++ b/src/db.zig @@ -90,7 +90,7 @@ pub const DB = struct { datasz: usize, rwtx: ?*tx.TX = null, - txs: std.ArrayList(*tx.TX), + txs: std.array_list.Managed(*tx.TX), // the freelist is used to manage the *dirty* pages in the transaction, it only changes at writable transaction, but has only writable transaction once. // So we don't need to lock the freelist and it is safe by rwlock. freelist: *freelist.FreeList, @@ -130,7 +130,7 @@ pub const DB = struct { /// Returns the string representation of the database. pub fn string(self: *const Self, _allocator: std.mem.Allocator) []u8 { - var buf = std.ArrayList(u8).init(_allocator); + var buf = std.array_list.Managed(u8).init(_allocator); defer buf.deinit(); const writer = buf.writer(); writer.print("meta0: {}\n", .{self.meta0.*}) catch unreachable; @@ -144,7 +144,7 @@ pub const DB = struct { /// Returns db pretty format string. pub fn pageString(self: *const Self, _allocator: std.mem.Allocator) []u8 { - var buf = std.ArrayList(u8).init(_allocator); + var buf = std.array_list.Managed(u8).init(_allocator); defer buf.deinit(); const writer = buf.writer(); writer.print("meta0:{}\n", .{self.pageById(0).*}) catch unreachable; @@ -179,7 +179,7 @@ pub const DB = struct { if (db.pageSize == 0) { db.pageSize = consts.PageSize; } - db.txs = std.ArrayList(*TX).init(allocator); + db.txs = std.array_list.Managed(*tx.TX).initCapacity(allocator, 0) catch unreachable; db.stats = Stats{}; db.readOnly = options.readOnly; db.strictMode = options.strictMode; @@ -333,9 +333,9 @@ pub const DB = struct { // log.err("mmap minsz: {}", .{minsz}); self.mmaplock.lock(); defer self.mmaplock.unlock(); - const fileInfo = try self.file.metadata(); + const fileInfo = try self.file.stat(); // ensure the size is at least the minmum size. - var size = @as(usize, fileInfo.size()); + var size = fileInfo.size; // TODO Delete it // assert(size >= minsz, "the size of file is less than the minsz: {d}, file size: {d}", .{ minsz, size }); if (size < minsz) { diff --git a/src/freelist.zig b/src/freelist.zig index 3e72cbd..95a1452 100644 --- a/src/freelist.zig +++ b/src/freelist.zig @@ -13,9 +13,9 @@ const log = std.log.scoped(.BoltFreeList); // It also tracks pages that have been freed but are still in use by open transactions. pub const FreeList = struct { // all free and available free page ids. - ids: std.ArrayList(PgidType), + ids: std.array_list.Managed(PgidType), // mapping of soon-to-be free page ids by tx. - pending: std.AutoHashMap(consts.TxId, std.ArrayList(PgidType)), + pending: std.AutoHashMap(consts.TxId, std.array_list.Managed(PgidType)), // fast lookup of all free and pending pgae ids. cache: std.AutoHashMap(PgidType, bool), @@ -26,8 +26,8 @@ pub const FreeList = struct { /// init freelist pub fn init(allocator: std.mem.Allocator) *Self { const f = allocator.create(Self) catch unreachable; - f.ids = std.ArrayList(PgidType).init(allocator); - f.pending = std.AutoHashMap(TxId, std.ArrayList(PgidType)).init(allocator); + f.ids = std.array_list.Managed(PgidType).init(allocator); + f.pending = std.AutoHashMap(TxId, std.array_list.Managed(PgidType)).init(allocator); f.cache = std.AutoHashMap(PgidType, bool).init(allocator); f.allocator = allocator; return f; @@ -81,7 +81,7 @@ pub const FreeList = struct { /// Copies into dst a list of all free ids and all pending ids in one sorted list. pub fn copyAll(self: *Self, dst: []PgidType) void { - var array = std.ArrayList(PgidType).initCapacity(self.allocator, self.pendingCount()) catch unreachable; + var array = std.array_list.Managed(PgidType).initCapacity(self.allocator, self.pendingCount()) catch unreachable; defer array.deinit(); var itr = self.pending.valueIterator(); while (itr.next()) |entries| { @@ -147,7 +147,7 @@ pub const FreeList = struct { pub fn free(self: *Self, txid: TxId, p: *const Page) !void { assert(p.id > 1, "can not free 0 or 1 page", .{}); // Free page and all its overflow pages. - const ids = try self.pending.getOrPutValue(txid, std.ArrayList(PgidType).init(self.allocator)); + const ids = try self.pending.getOrPutValue(txid, std.array_list.Managed(PgidType).init(self.allocator)); for (p.id..(p.id + p.overflow + 1)) |id| { // Add to the freelist and cache. try self.cache.putNoClobber(id, true); @@ -161,7 +161,7 @@ pub const FreeList = struct { if (!@import("builtin").is_test) { assert(self.pending.count() <= 1, "pending count should be less than 1", .{}); } - var arrayIDs = std.ArrayList(PgidType).init(self.allocator); + var arrayIDs = std.array_list.Managed(PgidType).init(self.allocator); defer arrayIDs.deinit(); var itr = self.pending.iterator(); while (itr.next()) |entry| { @@ -176,7 +176,7 @@ pub const FreeList = struct { } // Sort the array std.mem.sort(PgidType, arrayIDs.items, {}, std.sort.asc(PgidType)); - var array = try std.ArrayList(PgidType).initCapacity(self.allocator, arrayIDs.items.len + self.ids.items.len); + var array = try std.array_list.Managed(PgidType).initCapacity(self.allocator, arrayIDs.items.len + self.ids.items.len); defer array.deinit(); try array.appendNTimes(0, arrayIDs.items.len + self.ids.items.len); assert(array.items.len == (arrayIDs.items.len + self.ids.items.len), "array.items.len == (arrayIDs.items.len + self.ids.items.len)", .{}); @@ -273,7 +273,7 @@ pub const FreeList = struct { // Check each page in the freelist and build a new available freelist. // with any pages not in the pending lists. - var a = std.ArrayList(PgidType).init(self.allocator); + var a = std.array_list.Managed(PgidType).init(self.allocator); defer a.deinit(); for (self.ids.items) |id| { if (!pagaeCahe.contains(id)) { @@ -331,7 +331,7 @@ pub const FreeList = struct { /// Format freelist to string with _allocator. pub fn string(self: *Self, _allocator: std.mem.Allocator) []u8 { - var buf = std.ArrayList(u8).init(_allocator); + var buf = std.array_list.Managed(u8).init(_allocator); defer buf.deinit(); const writer = buf.writer(); @@ -444,9 +444,9 @@ pub const FreeList = struct { // defer freelist.deinit(); // try freelist.ids.appendSlice(&.{ 12, 39 }); -// var c100 = std.ArrayList(PgidType).init(std.testing.allocator); +// var c100 = std.array_list.Managed(PgidType).init(std.testing.allocator); // c100.appendSlice(&.{ 28, 11 }) catch unreachable; -// var c101 = std.ArrayList(PgidType).init(std.testing.allocator); +// var c101 = std.array_list.Managed(PgidType).init(std.testing.allocator); // c101.appendSlice(&.{3}) catch unreachable; // try freelist.pending.put(100, c100); // try freelist.pending.put(101, c101); @@ -491,7 +491,7 @@ pub const FreeList = struct { // // std.debug.print("{},", .{n}); // // } // // std.debug.print("\n", .{}); -// // var arr = try std.ArrayList(page.PgidType).initCapacity(std.heap.page_allocator, 100); +// // var arr = try std.array_list.Managed(page.PgidType).initCapacity(std.heap.page_allocator, 100); // // defer arr.deinit(); // // } @@ -499,7 +499,7 @@ pub const FreeList = struct { // // var flist = FreeList.init(std.testing.allocator); // // defer flist.deinit(); -// // var ids = std.ArrayList(page.PgidType).initCapacity(std.testing.allocator, 0) catch unreachable; +// // var ids = std.array_list.Managed(page.PgidType).initCapacity(std.testing.allocator, 0) catch unreachable; // // for (0..29) |i| { // // const pid = @as(u64, i); // // ids.append(pid) catch unreachable; diff --git a/src/gc.zig b/src/gc.zig index bf0f774..3d5cea0 100644 --- a/src/gc.zig +++ b/src/gc.zig @@ -51,7 +51,7 @@ pub const GC = struct { } } - pub fn addArrayList(self: *Self, list: std.ArrayList(u8)) !void { + pub fn addArrayList(self: *Self, list: std.array_list.Managed(u8)) !void { const bytes = try list.toOwnedSlice(); const allocator = list.allocator; try self.add(allocator, bytes); @@ -69,7 +69,7 @@ pub const GC = struct { /// A pool of pages that can be reused. pub const PagePool = struct { - free: std.ArrayList(*Page), + free: std.array_list.Managed(*Page), arena: std.heap.ArenaAllocator, lock: std.Thread.Mutex, // Protects meta page access. pageSize: usize = 0, @@ -77,7 +77,7 @@ pub const PagePool = struct { /// Initializes the PagePool with a given allocator and page size. pub fn init(allocator: std.mem.Allocator, pageSize: usize) @This() { - return .{ .arena = std.heap.ArenaAllocator.init(allocator), .free = std.ArrayList(*Page).init(allocator), .lock = .{}, .pageSize = pageSize }; + return .{ .arena = std.heap.ArenaAllocator.init(allocator), .free = std.array_list.Managed(*Page).init(allocator), .lock = .{}, .pageSize = pageSize }; } /// Deinitializes the PagePool and frees all allocated memory. @@ -92,7 +92,7 @@ pub const PagePool = struct { pub fn new(self: *@This()) !*Page { self.lock.lock(); defer self.lock.unlock(); - const p = if (self.free.popOrNull()) |hasPage| hasPage else { + const p = if (self.free.pop()) |hasPage| hasPage else { const buffer = try self.arena.allocator().alloc(u8, self.pageSize); @memset(buffer, 0); self.allocSize += buffer.len; diff --git a/src/node.zig b/src/node.zig index 78afdc5..9f71b60 100644 --- a/src/node.zig +++ b/src/node.zig @@ -46,8 +46,8 @@ pub const Node = struct { const id = std.crypto.random.int(u64); self.* = .{ .arenaAllocator = arenaAllocator, - .children = std.ArrayList(*Node).init(allocator), - .inodes = std.ArrayList(INode).init(allocator), + .children = std.array_list.Managed(*Node).init(allocator), + .inodes = std.array_list.Managed(INode).init(allocator), .id = id, }; return self; @@ -381,8 +381,8 @@ pub const Node = struct { /// Split breaks up a node into multiple smaller nodes, If appropriate. /// This should only be called from the spill() function. - pub fn split(self: *Self, _pageSize: usize) std.ArrayList(*Node) { - var nodes = std.ArrayList(*Node).init(self.arenaAllocator.allocator()); + pub fn split(self: *Self, _pageSize: usize) std.array_list.Managed(*Node) { + var nodes = std.array_list.Managed(*Node).init(self.arenaAllocator.allocator()); var curNode = self; while (true) { // Split node into two. @@ -794,7 +794,7 @@ pub const Node = struct { fn printKeysString(self: *Self) void { std.log.debug("--->>id:{}, pgid:{}, inodes len: {d}<<--", .{ self.id, self.pgid, self.inodes.items.len }); - var keyArray = std.ArrayList([]const u8).init(self.arenaAllocator.allocator()); + var keyArray = std.array_list.Managed([]const u8).init(self.arenaAllocator.allocator()); defer keyArray.deinit(); for (self.inodes.items) |inode| { const key = inode.key.?; @@ -888,6 +888,6 @@ pub const INode = struct { } }; -const INodes = std.ArrayList(INode); +const INodes = std.array_list.Managed(INode); -const Nodes = std.ArrayList(*Node); +const Nodes = std.array_list.Managed(*Node); diff --git a/src/pretty_table.zig b/src/pretty_table.zig index 346cd62..5f75709 100644 --- a/src/pretty_table.zig +++ b/src/pretty_table.zig @@ -29,8 +29,8 @@ pub const ResetColor = "\x1b[0m"; /// A table. pub const Table = struct { - headers: std.ArrayList([]const u8), - rows: std.ArrayList(std.ArrayList([]const u8)), + headers: std.array_list.Managed([]const u8), + rows: std.array_list.Managed(std.array_list.Managed([]const u8)), columnWidth: usize, allocator: std.mem.Allocator, headerColor: Color, @@ -39,8 +39,8 @@ pub const Table = struct { /// Init a table. pub fn init(allocator: std.mem.Allocator, columnWidth: usize, headerColor: Color, name: []const u8) @This() { return .{ - .headers = std.ArrayList([]const u8).init(allocator), - .rows = std.ArrayList(std.ArrayList([]const u8)).init(allocator), + .headers = std.array_list.Managed([]const u8).init(allocator), + .rows = std.array_list.Managed(std.array_list.Managed([]const u8)).init(allocator), .columnWidth = columnWidth, .allocator = allocator, .headerColor = headerColor, @@ -73,7 +73,7 @@ pub const Table = struct { /// Add a row to a table. pub fn addRow(self: *@This(), row: anytype) !void { - var rowList = std.ArrayList([]const u8).init(self.allocator); + var rowList = std.array_list.Managed([]const u8).init(self.allocator); inline for (row) |cell| { const cellStr = switch (@TypeOf(cell)) { u64, usize, i64, isize, u32, i32, u16, i16, u8, i8 => try std.fmt.allocPrint(self.allocator, "{d}", .{cell}), diff --git a/src/tests.zig b/src/tests.zig index fe387cd..36c508c 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -161,7 +161,7 @@ pub const Quick = struct { maxItems: usize = 10000, maxKeySize: usize = 1024, maxValueSize: usize = 1024, - items: std.ArrayList(TestDataItem) = undefined, + items: std.array_list.Managed(TestDataItem) = undefined, allocator: std.mem.Allocator, /// Initialize a Quick instance. @@ -183,10 +183,10 @@ pub const Quick = struct { } /// Generate a set of test data. - pub fn generate(self: *@This(), allocator: std.mem.Allocator) !std.ArrayList(TestDataItem) { + pub fn generate(self: *@This(), allocator: std.mem.Allocator) !std.array_list.Managed(TestDataItem) { var randItems = try RevTestData.generate(allocator, self); const slice = try randItems.toOwnedSlice(); - self.items = std.ArrayList(TestDataItem).fromOwnedSlice(self.allocator, slice); + self.items = std.array_list.Managed(TestDataItem).fromOwnedSlice(self.allocator, slice); return self.items; } @@ -205,7 +205,7 @@ pub const Quick = struct { std.mem.reverse(TestDataItem, self.items.items); } - pub fn checkWithContext(self: *@This(), context: anytype, config: ?Config, comptime travel: fn (@TypeOf(context)) Error!void) std.ArrayList(Error) { + pub fn checkWithContext(self: *@This(), context: anytype, config: ?Config, comptime travel: fn (@TypeOf(context)) Error!void) std.array_list.Managed(Error) { if (config == null) { config = .{ .rand = std.Random.DefaultPrng.init(0).random(), @@ -215,7 +215,7 @@ pub const Quick = struct { const randor = config.?.getRand(); _ = randor; // autofix - var errors = std.ArrayList(Error).init(self.allocator); + var errors = std.array_list.Managed(Error).init(self.allocator); for (0..maxCount) |i| { _ = i; // autofix @@ -275,11 +275,11 @@ pub const RevTestData = struct { pub fn generate( allocator: std.mem.Allocator, q: *const Quick, - ) !std.ArrayList(TestDataItem) { + ) !std.array_list.Managed(TestDataItem) { var prng = std.Random.DefaultPrng.init(q.seed); var random = prng.random(); const n = random.intRangeAtMost(usize, 1, q.maxItems); - var items = std.ArrayList(TestDataItem).init(allocator); + var items = std.array_list.Managed(TestDataItem).init(allocator); try items.appendNTimes(TestDataItem{ .key = undefined, .value = undefined }, n); var used = std.StringHashMap(bool).init(allocator); defer used.deinit(); @@ -316,7 +316,7 @@ pub const RevTestData = struct { /// A copy writer. pub const CopyWriter = struct { - buffer: std.ArrayList(u8), + buffer: std.array_list.Managed(u8), /// Append bytes to the buffer. pub fn appendWriter(self: *CopyWriter, bytes: []const u8) error{OutOfMemory}!usize { try self.buffer.appendSlice(bytes); diff --git a/src/tx.zig b/src/tx.zig index 97da992..afda39e 100644 --- a/src/tx.zig +++ b/src/tx.zig @@ -98,7 +98,7 @@ pub const TX = struct { var buf: [1024]u8 = undefined; - var nodesKeys = std.ArrayList(u8).init(self.allocator); + var nodesKeys = std.array_list.Managed(u8).init(self.allocator); defer nodesKeys.deinit(); try nodesKeys.appendSlice(try std.fmt.bufPrint(&buf, "count:{}\t", .{self.root.nodes.count()})); var nodesItr = self.root.nodes.iterator(); @@ -364,7 +364,7 @@ pub const TX = struct { pub fn write(self: *Self) Error!void { // Sort pages by id. const cap: usize = if (self.pages != null) self.pages.?.count() else 0; - var pagesSlice = try std.ArrayList(*page.Page).initCapacity(self.allocator, cap); + var pagesSlice = try std.array_list.Managed(*page.Page).initCapacity(self.allocator, cap); defer pagesSlice.deinit(); // If the transaction is writable, the pages must be not null. var itr = self.pages.?.valueIterator(); diff --git a/src/util.zig b/src/util.zig index a125078..79a93c0 100644 --- a/src/util.zig +++ b/src/util.zig @@ -53,7 +53,7 @@ pub fn mmap(fp: std.fs.File, fileSize: u64, writeable: bool) ![]u8 { pub fn munmap(ptr: []u8) void { // std.debug.print("the ptr size: {}, {}\n", .{ ptr.len, std.mem.page_size }); - const alignData: []align(std.mem.page_size) const u8 = @alignCast(ptr); + const alignData: []align(std.heap.page_size_min) const u8 = @alignCast(ptr); if (isLinux() or isMacOS()) { std.posix.munmap(alignData); } else {