| ... | ... | @@ -157,13 +157,13 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 157 | 157 | |
| 158 | 158 | /// Invalidates all element pointers. |
| 159 | 159 | pub fn clearRetainingCapacity(self: *Self) void { |
| 160 | | self.items.len = 0; |
| 160 | self.len = 0; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /// Invalidates all element pointers. |
| 164 | 164 | pub fn clearAndFree(self: *Self, allocator: Allocator) void { |
| 165 | 165 | self.setCapacity(allocator, 0) catch unreachable; |
| 166 | | self.items.len = 0; |
| 166 | self.len = 0; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /// Grows or shrinks capacity to match usage. |
| ... | ... | @@ -403,15 +403,13 @@ test "SegmentedList basic usage" { |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | fn testSegmentedList(comptime prealloc: usize) !void { |
| 406 | | const gpa = std.testing.allocator; |
| 407 | | |
| 408 | | var list: SegmentedList(i32, prealloc) = .{}; |
| 409 | | defer list.deinit(gpa); |
| 406 | var list = SegmentedList(i32, prealloc){}; |
| 407 | defer list.deinit(testing.allocator); |
| 410 | 408 | |
| 411 | 409 | { |
| 412 | 410 | var i: usize = 0; |
| 413 | 411 | while (i < 100) : (i += 1) { |
| 414 | | try list.append(gpa, @intCast(i32, i + 1)); |
| 412 | try list.append(testing.allocator, @intCast(i32, i + 1)); |
| 415 | 413 | try testing.expect(list.len == i + 1); |
| 416 | 414 | } |
| 417 | 415 | } |
| ... | ... | @@ -454,21 +452,21 @@ fn testSegmentedList(comptime prealloc: usize) !void { |
| 454 | 452 | try testing.expect(list.pop().? == 100); |
| 455 | 453 | try testing.expect(list.len == 99); |
| 456 | 454 | |
| 457 | | try list.appendSlice(gpa, &[_]i32{ 1, 2, 3 }); |
| 455 | try list.appendSlice(testing.allocator, &[_]i32{ 1, 2, 3 }); |
| 458 | 456 | try testing.expect(list.len == 102); |
| 459 | 457 | try testing.expect(list.pop().? == 3); |
| 460 | 458 | try testing.expect(list.pop().? == 2); |
| 461 | 459 | try testing.expect(list.pop().? == 1); |
| 462 | 460 | try testing.expect(list.len == 99); |
| 463 | 461 | |
| 464 | | try list.appendSlice(gpa, &[_]i32{}); |
| 462 | try list.appendSlice(testing.allocator, &[_]i32{}); |
| 465 | 463 | try testing.expect(list.len == 99); |
| 466 | 464 | |
| 467 | 465 | { |
| 468 | 466 | var i: i32 = 99; |
| 469 | 467 | while (list.pop()) |item| : (i -= 1) { |
| 470 | 468 | try testing.expect(item == i); |
| 471 | | list.shrinkCapacity(gpa, list.len); |
| 469 | list.shrinkCapacity(testing.allocator, list.len); |
| 472 | 470 | } |
| 473 | 471 | } |
| 474 | 472 | |
| ... | ... | @@ -478,7 +476,7 @@ fn testSegmentedList(comptime prealloc: usize) !void { |
| 478 | 476 | |
| 479 | 477 | var i: i32 = 0; |
| 480 | 478 | while (i < 100) : (i += 1) { |
| 481 | | try list.append(gpa, i + 1); |
| 479 | try list.append(testing.allocator, i + 1); |
| 482 | 480 | control[@intCast(usize, i)] = i + 1; |
| 483 | 481 | } |
| 484 | 482 | |
| ... | ... | @@ -491,7 +489,20 @@ fn testSegmentedList(comptime prealloc: usize) !void { |
| 491 | 489 | try testing.expect(std.mem.eql(i32, control[50..], dest[50..])); |
| 492 | 490 | } |
| 493 | 491 | |
| 494 | | try list.setCapacity(gpa, 0); |
| 492 | try list.setCapacity(testing.allocator, 0); |
| 493 | } |
| 494 | |
| 495 | test "std.segmented_list clearRetainingCapacity" { |
| 496 | var list = SegmentedList(i32, 1){}; |
| 497 | defer list.deinit(testing.allocator); |
| 498 | |
| 499 | try list.appendSlice(testing.allocator, &[_]i32{ 4, 5 }); |
| 500 | list.clearRetainingCapacity(); |
| 501 | try list.append(testing.allocator, 6); |
| 502 | try testing.expect(list.at(0).* == 6); |
| 503 | try testing.expect(list.len == 1); |
| 504 | list.clearRetainingCapacity(); |
| 505 | try testing.expect(list.len == 0); |
| 495 | 506 | } |
| 496 | 507 | |
| 497 | 508 | /// TODO look into why this std.math function was changed in |