| ... | ... | @@ -476,24 +476,24 @@ pub const DynamicBitSetUnmanaged = struct { |
| 476 | 476 | |
| 477 | 477 | /// Creates a bit set with no elements present. |
| 478 | 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 | 480 | var self = Self{}; |
| 481 | | try self.resize(bit_length, false, allocator); |
| 481 | try self.resize(allocator, bit_length, false); |
| 482 | 482 | return self; |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /// Creates a bit set with all elements present. |
| 486 | 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 | 488 | var self = Self{}; |
| 489 | | try self.resize(bit_length, true, allocator); |
| 489 | try self.resize(allocator, bit_length, true); |
| 490 | 490 | return self; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /// Resizes to a new bit_length. If the new length is larger |
| 494 | 494 | /// than the old length, fills any added bits with `fill`. |
| 495 | 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 | 497 | const old_len = self.bit_length; |
| 498 | 498 | |
| 499 | 499 | const old_masks = numMasks(old_len); |
| ... | ... | @@ -557,14 +557,14 @@ pub const DynamicBitSetUnmanaged = struct { |
| 557 | 557 | /// The passed allocator must be the same one used for |
| 558 | 558 | /// init* or resize in the past. |
| 559 | 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 | } |
| 562 | 562 | |
| 563 | 563 | /// Creates a duplicate of this bit set, using the new allocator. |
| 564 | 564 | pub fn clone(self: *const Self, new_allocator: Allocator) !Self { |
| 565 | 565 | const num_masks = numMasks(self.bit_length); |
| 566 | 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 | 568 | std.mem.copy(MaskInt, copy.masks[0..num_masks], self.masks[0..num_masks]); |
| 569 | 569 | return copy; |
| 570 | 570 | } |
| ... | ... | @@ -748,17 +748,17 @@ pub const DynamicBitSet = struct { |
| 748 | 748 | unmanaged: DynamicBitSetUnmanaged = .{}, |
| 749 | 749 | |
| 750 | 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 | 752 | return Self{ |
| 753 | | .unmanaged = try DynamicBitSetUnmanaged.initEmpty(bit_length, allocator), |
| 753 | .unmanaged = try DynamicBitSetUnmanaged.initEmpty(allocator, bit_length), |
| 754 | 754 | .allocator = allocator, |
| 755 | 755 | }; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 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 | 760 | return Self{ |
| 761 | | .unmanaged = try DynamicBitSetUnmanaged.initFull(bit_length, allocator), |
| 761 | .unmanaged = try DynamicBitSetUnmanaged.initFull(allocator, bit_length), |
| 762 | 762 | .allocator = allocator, |
| 763 | 763 | }; |
| 764 | 764 | } |
| ... | ... | @@ -766,7 +766,7 @@ pub const DynamicBitSet = struct { |
| 766 | 766 | /// Resizes to a new length. If the new length is larger |
| 767 | 767 | /// than the old length, fills any added bits with `fill`. |
| 768 | 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 | } |
| 771 | 771 | |
| 772 | 772 | /// deinitializes the array and releases its memory. |
| ... | ... | @@ -1182,11 +1182,11 @@ test "ArrayBitSet" { |
| 1182 | 1182 | |
| 1183 | 1183 | test "DynamicBitSetUnmanaged" { |
| 1184 | 1184 | const allocator = std.testing.allocator; |
| 1185 | | var a = try DynamicBitSetUnmanaged.initEmpty(300, allocator); |
| 1185 | var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300); |
| 1186 | 1186 | try testing.expectEqual(@as(usize, 0), a.count()); |
| 1187 | 1187 | a.deinit(allocator); |
| 1188 | 1188 | |
| 1189 | | a = try DynamicBitSetUnmanaged.initEmpty(0, allocator); |
| 1189 | a = try DynamicBitSetUnmanaged.initEmpty(allocator, 0); |
| 1190 | 1190 | defer a.deinit(allocator); |
| 1191 | 1191 | for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| { |
| 1192 | 1192 | const old_len = a.capacity(); |
| ... | ... | @@ -1202,8 +1202,8 @@ test "DynamicBitSetUnmanaged" { |
| 1202 | 1202 | a.toggleSet(a); // zero a |
| 1203 | 1203 | tmp.toggleSet(tmp); |
| 1204 | 1204 | |
| 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); |
| 1207 | 1207 | |
| 1208 | 1208 | if (size > old_len) { |
| 1209 | 1209 | try testing.expectEqual(size - old_len, a.count()); |
| ... | ... | @@ -1212,7 +1212,7 @@ test "DynamicBitSetUnmanaged" { |
| 1212 | 1212 | } |
| 1213 | 1213 | try testing.expectEqual(@as(usize, 0), tmp.count()); |
| 1214 | 1214 | |
| 1215 | | var b = try DynamicBitSetUnmanaged.initFull(size, allocator); |
| 1215 | var b = try DynamicBitSetUnmanaged.initFull(allocator, size); |
| 1216 | 1216 | defer b.deinit(allocator); |
| 1217 | 1217 | try testing.expectEqual(@as(usize, size), b.count()); |
| 1218 | 1218 | |
| ... | ... | @@ -1222,11 +1222,11 @@ test "DynamicBitSetUnmanaged" { |
| 1222 | 1222 | |
| 1223 | 1223 | test "DynamicBitSet" { |
| 1224 | 1224 | const allocator = std.testing.allocator; |
| 1225 | | var a = try DynamicBitSet.initEmpty(300, allocator); |
| 1225 | var a = try DynamicBitSet.initEmpty(allocator, 300); |
| 1226 | 1226 | try testing.expectEqual(@as(usize, 0), a.count()); |
| 1227 | 1227 | a.deinit(); |
| 1228 | 1228 | |
| 1229 | | a = try DynamicBitSet.initEmpty(0, allocator); |
| 1229 | a = try DynamicBitSet.initEmpty(allocator, 0); |
| 1230 | 1230 | defer a.deinit(); |
| 1231 | 1231 | for ([_]usize{ 1, 2, 31, 32, 33, 0, 65, 64, 63, 500, 254, 3000 }) |size| { |
| 1232 | 1232 | const old_len = a.capacity(); |
| ... | ... | @@ -1252,7 +1252,7 @@ test "DynamicBitSet" { |
| 1252 | 1252 | } |
| 1253 | 1253 | try testing.expectEqual(@as(usize, 0), tmp.count()); |
| 1254 | 1254 | |
| 1255 | | var b = try DynamicBitSet.initFull(size, allocator); |
| 1255 | var b = try DynamicBitSet.initFull(allocator, size); |
| 1256 | 1256 | defer b.deinit(); |
| 1257 | 1257 | try testing.expectEqual(@as(usize, size), b.count()); |
| 1258 | 1258 | |