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 {
476476
477477 /// Creates a bit set with no elements present.
478478 /// 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 {
480480 var self = Self{};
481 try self.resize(bit_length, false, allocator);
481 try self.resize(allocator, bit_length, false);
482482 return self;
483483 }
484484
485485 /// Creates a bit set with all elements present.
486486 /// 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 {
488488 var self = Self{};
489 try self.resize(bit_length, true, allocator);
489 try self.resize(allocator, bit_length, true);
490490 return self;
491491 }
492492
493493 /// Resizes to a new bit_length. If the new length is larger
494494 /// than the old length, fills any added bits with `fill`.
495495 /// 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 {
497497 const old_len = self.bit_length;
498498
499499 const old_masks = numMasks(old_len);
......@@ -557,14 +557,14 @@ pub const DynamicBitSetUnmanaged = struct {
557557 /// The passed allocator must be the same one used for
558558 /// init* or resize in the past.
559559 pub fn deinit(self: *Self, allocator: Allocator) void {
560 self.resize(0, false, allocator) catch unreachable;
560 self.resize(allocator, 0, false) catch unreachable;
561561 }
562562
563563 /// Creates a duplicate of this bit set, using the new allocator.
564564 pub fn clone(self: *const Self, new_allocator: Allocator) !Self {
565565 const num_masks = numMasks(self.bit_length);
566566 var copy = Self{};
567 try copy.resize(self.bit_length, false, new_allocator);
567 try copy.resize(new_allocator, self.bit_length, false);
568568 std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]);
569569 return copy;
570570 }
......@@ -748,17 +748,17 @@ pub const DynamicBitSet = struct {
748748 unmanaged: DynamicBitSetUnmanaged = .{},
749749
750750 /// 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 {
752752 return Self{
753 .unmanaged = try DynamicBitSetUnmanaged.initEmpty(bit_length, allocator),
753 .unmanaged = try DynamicBitSetUnmanaged.initEmpty(allocator, bit_length),
754754 .allocator = allocator,
755755 };
756756 }
757757
758758 /// 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 {
760760 return Self{
761 .unmanaged = try DynamicBitSetUnmanaged.initFull(bit_length, allocator),
761 .unmanaged = try DynamicBitSetUnmanaged.initFull(allocator, bit_length),
762762 .allocator = allocator,
763763 };
764764 }
......@@ -766,7 +766,7 @@ pub const DynamicBitSet = struct {
766766 /// Resizes to a new length. If the new length is larger
767767 /// than the old length, fills any added bits with `fill`.
768768 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);
770770 }
771771
772772 /// deinitializes the array and releases its memory.
......@@ -1182,11 +1182,11 @@ test "ArrayBitSet" {
11821182
11831183test "DynamicBitSetUnmanaged" {
11841184 const allocator = std.testing.allocator;
1185 var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator);
1185 var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);
11861186 try testing.expectEqual(@as(usize, 0), a.count());
11871187 a.deinit(allocator);
11881188
1189 a = try DynamicBitSetUnmanaged.initEmpty(0, allocator);
1189 a = try DynamicBitSetUnmanaged.initEmpty(allocator, 0);
11901190 defer a.deinit(allocator);
11911191 for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| {
11921192 const old_len = a.capacity();
......@@ -1202,8 +1202,8 @@ test "DynamicBitSetUnmanaged" {
12021202 a.toggleSet(a); // zero a
12031203 tmp.toggleSet(tmp);
12041204
1205 try a.resize(size, true, allocator);
1206 try tmp.resize(size, false, allocator);
1205 try a.resize(allocator, size, true);
1206 try tmp.resize(allocator, size, false);
12071207
12081208 if (size > old_len) {
12091209 try testing.expectEqual(size - old_len, a.count());
......@@ -1212,7 +1212,7 @@ test "DynamicBitSetUnmanaged" {
12121212 }
12131213 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);
12161216 defer b.deinit(allocator);
12171217 try testing.expectEqual(@as(usize, size), b.count());
12181218
......@@ -1222,11 +1222,11 @@ test "DynamicBitSetUnmanaged" {
12221222
12231223test "DynamicBitSet" {
12241224 const allocator = std.testing.allocator;
1225 var a = try DynamicBitSet.initEmpty(300, allocator);
1225 var a = try DynamicBitSet.initEmpty(allocator, 300);
12261226 try testing.expectEqual(@as(usize, 0), a.count());
12271227 a.deinit();
12281228
1229 a = try DynamicBitSet.initEmpty(0, allocator);
1229 a = try DynamicBitSet.initEmpty(allocator, 0);
12301230 defer a.deinit();
12311231 for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| {
12321232 const old_len = a.capacity();
......@@ -1252,7 +1252,7 @@ test "DynamicBitSet" {
12521252 }
12531253 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);
12561256 defer b.deinit();
12571257 try testing.expectEqual(@as(usize, size), b.count());
12581258