authorgravatar for dev@jakubdupak.comJakub Dupak <dev@jakubdupak.com> 2021-12-01 13:27:00+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-03 16:42:59-08:00
logbb75f5d29709c7593dfe7269f70515919ff25c74
tree4dda8794d11f24cb8f2cd412039581b06c3510bb
parent9354ad82782f72a05663b64fcfd839d2aa98e878

9944: make allocator the first argument (excl. self)


1 files changed, 20 insertions(+), 20 deletions(-)

lib/std/bit_set.zig+20-20
...@@ -476,24 +476,24 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -476,24 +476,24 @@ pub const DynamicBitSetUnmanaged = struct {
476476
477 /// Creates a bit set with no elements present.477 /// Creates a bit set with no elements present.
478 /// If bit_length is not zero, deinit must eventually be called.478 /// If bit_length is not zero, deinit must eventually be called.
479 pub fn initEmpty(bit_length: usize, allocator: Allocator) !Self {479 pub fn initEmpty(allocator: Allocator, bit_length: usize) !Self {
480 var self = Self{};480 var self = Self{};
481 try self.resize(bit_length, false, allocator);481 try self.resize(allocator, bit_length, false);
482 return self;482 return self;
483 }483 }
484484
485 /// Creates a bit set with all elements present.485 /// Creates a bit set with all elements present.
486 /// If bit_length is not zero, deinit must eventually be called.486 /// If bit_length is not zero, deinit must eventually be called.
487 pub fn initFull(bit_length: usize, allocator: Allocator) !Self {487 pub fn initFull(allocator: Allocator, bit_length: usize) !Self {
488 var self = Self{};488 var self = Self{};
489 try self.resize(bit_length, true, allocator);489 try self.resize(allocator, bit_length, true);
490 return self;490 return self;
491 }491 }
492492
493 /// Resizes to a new bit_length. If the new length is larger493 /// Resizes to a new bit_length. If the new length is larger
494 /// than the old length, fills any added bits with `fill`.494 /// than the old length, fills any added bits with `fill`.
495 /// If new_len is not zero, deinit must eventually be called.495 /// If new_len is not zero, deinit must eventually be called.
496 pub fn resize(self: *@This(), new_len: usize, fill: bool, allocator: Allocator) !void {496 pub fn resize(self: *@This(), allocator: Allocator, new_len: usize, fill: bool) !void {
497 const old_len = self.bit_length;497 const old_len = self.bit_length;
498498
499 const old_masks = numMasks(old_len);499 const old_masks = numMasks(old_len);
...@@ -557,14 +557,14 @@ pub const DynamicBitSetUnmanaged = struct {...@@ -557,14 +557,14 @@ pub const DynamicBitSetUnmanaged = struct {
557 /// The passed allocator must be the same one used for557 /// The passed allocator must be the same one used for
558 /// init* or resize in the past.558 /// init* or resize in the past.
559 pub fn deinit(self: *Self, allocator: Allocator) void {559 pub fn deinit(self: *Self, allocator: Allocator) void {
560 self.resize(0, false, allocator) catch unreachable;560 self.resize(allocator, 0, false) catch unreachable;
561 }561 }
562562
563 /// Creates a duplicate of this bit set, using the new allocator.563 /// Creates a duplicate of this bit set, using the new allocator.
564 pub fn clone(self: *const Self, new_allocator: Allocator) !Self {564 pub fn clone(self: *const Self, new_allocator: Allocator) !Self {
565 const num_masks = numMasks(self.bit_length);565 const num_masks = numMasks(self.bit_length);
566 var copy = Self{};566 var copy = Self{};
567 try copy.resize(self.bit_length, false, new_allocator);567 try copy.resize(new_allocator, self.bit_length, false);
568 std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]);568 std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]);
569 return copy;569 return copy;
570 }570 }
...@@ -748,17 +748,17 @@ pub const DynamicBitSet = struct {...@@ -748,17 +748,17 @@ pub const DynamicBitSet = struct {
748 unmanaged: DynamicBitSetUnmanaged = .{},748 unmanaged: DynamicBitSetUnmanaged = .{},
749749
750 /// Creates a bit set with no elements present.750 /// Creates a bit set with no elements present.
751 pub fn initEmpty(bit_length: usize, allocator: Allocator) !Self {751 pub fn initEmpty(allocator: Allocator, bit_length: usize) !Self {
752 return Self{752 return Self{
753 .unmanaged = try DynamicBitSetUnmanaged.initEmpty(bit_length, allocator),753 .unmanaged = try DynamicBitSetUnmanaged.initEmpty(allocator, bit_length),
754 .allocator = allocator,754 .allocator = allocator,
755 };755 };
756 }756 }
757757
758 /// Creates a bit set with all elements present.758 /// Creates a bit set with all elements present.
759 pub fn initFull(bit_length: usize, allocator: Allocator) !Self {759 pub fn initFull(allocator: Allocator, bit_length: usize) !Self {
760 return Self{760 return Self{
761 .unmanaged = try DynamicBitSetUnmanaged.initFull(bit_length, allocator),761 .unmanaged = try DynamicBitSetUnmanaged.initFull(allocator, bit_length),
762 .allocator = allocator,762 .allocator = allocator,
763 };763 };
764 }764 }
...@@ -766,7 +766,7 @@ pub const DynamicBitSet = struct {...@@ -766,7 +766,7 @@ pub const DynamicBitSet = struct {
766 /// Resizes to a new length. If the new length is larger766 /// Resizes to a new length. If the new length is larger
767 /// than the old length, fills any added bits with `fill`.767 /// than the old length, fills any added bits with `fill`.
768 pub fn resize(self: *@This(), new_len: usize, fill: bool) !void {768 pub fn resize(self: *@This(), new_len: usize, fill: bool) !void {
769 try self.unmanaged.resize(new_len, fill, self.allocator);769 try self.unmanaged.resize(self.allocator, new_len, fill);
770 }770 }
771771
772 /// deinitializes the array and releases its memory.772 /// deinitializes the array and releases its memory.
...@@ -1182,11 +1182,11 @@ test "ArrayBitSet" {...@@ -1182,11 +1182,11 @@ test "ArrayBitSet" {
11821182
1183test "DynamicBitSetUnmanaged" {1183test "DynamicBitSetUnmanaged" {
1184 const allocator = std.testing.allocator;1184 const allocator = std.testing.allocator;
1185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);1185 var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);
1186 try testing.expectEqual(@as(usize, 0), a.count());1186 try testing.expectEqual(@as(usize, 0), a.count());
1187 a.deinit(allocator);1187 a.deinit(allocator);
11881188
1189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);1189 a = try DynamicBitSetUnmanaged.initEmpty(allocator, 0);
1190 defer a.deinit(allocator);1190 defer a.deinit(allocator);
1191 for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| {1191 for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| {
1192 const old_len = a.capacity();1192 const old_len = a.capacity();
...@@ -1202,8 +1202,8 @@ test "DynamicBitSetUnmanaged" {...@@ -1202,8 +1202,8 @@ test "DynamicBitSetUnmanaged" {
1202 a.toggleSet(a); // zero a1202 a.toggleSet(a); // zero a
1203 tmp.toggleSet(tmp);1203 tmp.toggleSet(tmp);
12041204
1205 try a.resize(size, true, allocator);1205 try a.resize(allocator, size, true);
1206 try tmp.resize(size, false, allocator);1206 try tmp.resize(allocator, size, false);
12071207
1208 if (size > old_len) {1208 if (size > old_len) {
1209 try testing.expectEqual(size - old_len, a.count());1209 try testing.expectEqual(size - old_len, a.count());
...@@ -1212,7 +1212,7 @@ test "DynamicBitSetUnmanaged" {...@@ -1212,7 +1212,7 @@ test "DynamicBitSetUnmanaged" {
1212 }1212 }
1213 try testing.expectEqual(@as(usize, 0), tmp.count());1213 try testing.expectEqual(@as(usize, 0), tmp.count());
12141214
1215 var b = try DynamicBitSetUnmanaged.initFull(size, allocator);1215 var b = try DynamicBitSetUnmanaged.initFull(allocator, size);
1216 defer b.deinit(allocator);1216 defer b.deinit(allocator);
1217 try testing.expectEqual(@as(usize, size), b.count());1217 try testing.expectEqual(@as(usize, size), b.count());
12181218
...@@ -1222,11 +1222,11 @@ test "DynamicBitSetUnmanaged" {...@@ -1222,11 +1222,11 @@ test "DynamicBitSetUnmanaged" {
12221222
1223test "DynamicBitSet" {1223test "DynamicBitSet" {
1224 const allocator = std.testing.allocator;1224 const allocator = std.testing.allocator;
1225 var a = try DynamicBitSet.initEmpty(300, allocator);1225 var a = try DynamicBitSet.initEmpty(allocator, 300);
1226 try testing.expectEqual(@as(usize, 0), a.count());1226 try testing.expectEqual(@as(usize, 0), a.count());
1227 a.deinit();1227 a.deinit();
12281228
1229 a = try DynamicBitSet.initEmpty(0, allocator);1229 a = try DynamicBitSet.initEmpty(allocator, 0);
1230 defer a.deinit();1230 defer a.deinit();
1231 for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| {1231 for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| {
1232 const old_len = a.capacity();1232 const old_len = a.capacity();
...@@ -1252,7 +1252,7 @@ test "DynamicBitSet" {...@@ -1252,7 +1252,7 @@ test "DynamicBitSet" {
1252 }1252 }
1253 try testing.expectEqual(@as(usize, 0), tmp.count());1253 try testing.expectEqual(@as(usize, 0), tmp.count());
12541254
1255 var b = try DynamicBitSet.initFull(size, allocator);1255 var b = try DynamicBitSet.initFull(allocator, size);
1256 defer b.deinit();1256 defer b.deinit();
1257 try testing.expectEqual(@as(usize, size), b.count());1257 try testing.expectEqual(@as(usize, size), b.count());
12581258