From 0785c424b9ec91ef6434ed68356c8353d6577049 Mon Sep 17 00:00:00 2001 From: Eugene Rossokha Date: Sun, 23 Mar 2025 13:12:47 +0200 Subject: [PATCH] btree/rangemap: rename .new to .init --- src/util/btree.zig | 12 ++++++------ src/util/rangemap.zig | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/util/btree.zig b/src/util/btree.zig index 99c9010..887b43f 100644 --- a/src/util/btree.zig +++ b/src/util/btree.zig @@ -57,7 +57,7 @@ pub fn BTree(comptime N: type, comptime compare_fn: CompareFn(N), comptime deini left: ?*Node = null, right: ?*Node = null, - fn new(a: Allocator, key: N) Error!*Node { + fn init(a: Allocator, key: N) Error!*Node { const node = try a.create(Node); node.* = .{ .key = key, @@ -98,7 +98,7 @@ pub fn BTree(comptime N: type, comptime compare_fn: CompareFn(N), comptime deini } return .{ n, inserted }; } else { - const n = try Node.new(a, key); + const n = try Node.init(a, key); return .{ n, n }; } } @@ -185,7 +185,7 @@ pub fn BTree(comptime N: type, comptime compare_fn: CompareFn(N), comptime deini } }; - pub fn new(a: std.mem.Allocator) @This() { + pub fn init(a: std.mem.Allocator) @This() { return .{ .gpa = a }; } @@ -274,7 +274,7 @@ test "BTree insertion/removal" { } }.call; const Tree = BTree(u32, int_compare_fn, null); - var tree = Tree.new(std.testing.allocator); + var tree = Tree.init(std.testing.allocator); defer tree.deinit(); for (50..100) |i| { @@ -319,7 +319,7 @@ test "BTree removal by node" { } }.call; const Tree = BTree(u32, int_compare_fn, null); - var tree = Tree.new(std.testing.allocator); + var tree = Tree.init(std.testing.allocator); defer tree.deinit(); _ = try tree.insert(10); @@ -349,7 +349,7 @@ test "BTree iterator" { } }.call; const Tree = BTree(u32, int_compare_fn, null); - var tree = Tree.new(std.testing.allocator); + var tree = Tree.init(std.testing.allocator); defer tree.deinit(); for (50..100) |i| { diff --git a/src/util/rangemap.zig b/src/util/rangemap.zig index 3c958a9..4a5e957 100644 --- a/src/util/rangemap.zig +++ b/src/util/rangemap.zig @@ -46,8 +46,8 @@ pub fn RangeMap(comptime K: type, comptime V: type, comptime deinit_fn: ?fn (*V) btree: Tree, - pub fn new(gpa: Allocator) @This() { - return .{ .btree = Tree.new(gpa) }; + pub fn init(gpa: Allocator) @This() { + return .{ .btree = Tree.init(gpa) }; } pub fn deinit(self: *@This()) void { @@ -148,7 +148,7 @@ pub fn RangeMap(comptime K: type, comptime V: type, comptime deinit_fn: ?fn (*V) test "Range map insertion" { const Map = RangeMap(u32, []const u8, null); - var map = Map.new(std.testing.allocator); + var map = Map.init(std.testing.allocator); defer map.deinit(); _ = try map.insert(10, 10, "Range 2"); @@ -162,7 +162,7 @@ test "Range map insertion" { test "Range map get scalar" { const Map = RangeMap(u32, []const u8, null); - var map = Map.new(std.testing.allocator); + var map = Map.init(std.testing.allocator); defer map.deinit(); _ = try map.insert(10, 10, "Range [10..20)"); @@ -196,7 +196,7 @@ test "Range map get scalar" { test "Range map split" { const Map = RangeMap(u32, []const u8, null); - var map = Map.new(std.testing.allocator); + var map = Map.init(std.testing.allocator); defer map.deinit(); _ = try map.insert(0x1000, 0x1000, "Range [0x1000..0x2000)"); @@ -223,7 +223,7 @@ test "Range map split" { test "Range map iterator" { const Map = RangeMap(u32, []const u8, null); - var map = Map.new(std.testing.allocator); + var map = Map.init(std.testing.allocator); defer map.deinit(); _ = try map.insert(0x1000, 0x1000, "Range [0x1000..0x2000)");