| ... | ... | @@ -116,6 +116,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 116 | 116 | |
| 117 | 117 | /// Insert `item` at index `n` by moving `list[n .. list.len]` to make room. |
| 118 | 118 | /// This operation is O(N). |
| 119 | /// Invalidates pointers if additional memory is needed. |
| 119 | 120 | pub fn insert(self: *Self, n: usize, item: T) Allocator.Error!void { |
| 120 | 121 | try self.ensureUnusedCapacity(1); |
| 121 | 122 | self.items.len += 1; |
| ... | ... | @@ -126,6 +127,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 126 | 127 | |
| 127 | 128 | /// Insert slice `items` at index `i` by moving `list[i .. list.len]` to make room. |
| 128 | 129 | /// This operation is O(N). |
| 130 | /// Invalidates pointers if additional memory is needed. |
| 129 | 131 | pub fn insertSlice(self: *Self, i: usize, items: []const T) Allocator.Error!void { |
| 130 | 132 | try self.ensureUnusedCapacity(items.len); |
| 131 | 133 | self.items.len += items.len; |
| ... | ... | @@ -163,6 +165,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 163 | 165 | } |
| 164 | 166 | |
| 165 | 167 | /// Extend the list by 1 element. Allocates more memory as necessary. |
| 168 | /// Invalidates pointers if additional memory is needed. |
| 166 | 169 | pub fn append(self: *Self, item: T) Allocator.Error!void { |
| 167 | 170 | const new_item_ptr = try self.addOne(); |
| 168 | 171 | new_item_ptr.* = item; |
| ... | ... | @@ -205,6 +208,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 205 | 208 | |
| 206 | 209 | /// Append the slice of items to the list. Allocates more |
| 207 | 210 | /// memory as necessary. |
| 211 | /// Invalidates pointers if additional memory is needed. |
| 208 | 212 | pub fn appendSlice(self: *Self, items: []const T) Allocator.Error!void { |
| 209 | 213 | try self.ensureUnusedCapacity(items.len); |
| 210 | 214 | self.appendSliceAssumeCapacity(items); |
| ... | ... | @@ -223,6 +227,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 223 | 227 | /// Append an unaligned slice of items to the list. Allocates more |
| 224 | 228 | /// memory as necessary. Only call this function if calling |
| 225 | 229 | /// `appendSlice` instead would be a compile error. |
| 230 | /// Invalidates pointers if additional memory is needed. |
| 226 | 231 | pub fn appendUnalignedSlice(self: *Self, items: []align(1) const T) Allocator.Error!void { |
| 227 | 232 | try self.ensureUnusedCapacity(items.len); |
| 228 | 233 | self.appendUnalignedSliceAssumeCapacity(items); |
| ... | ... | @@ -257,6 +262,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 257 | 262 | |
| 258 | 263 | /// Same as `append` except it returns the number of bytes written, which is always the same |
| 259 | 264 | /// as `m.len`. The purpose of this function existing is to match `std.io.Writer` API. |
| 265 | /// Invalidates pointers if additional memory is needed. |
| 260 | 266 | fn appendWrite(self: *Self, m: []const u8) Allocator.Error!usize { |
| 261 | 267 | try self.appendSlice(m); |
| 262 | 268 | return m.len; |
| ... | ... | @@ -264,6 +270,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 264 | 270 | |
| 265 | 271 | /// Append a value to the list `n` times. |
| 266 | 272 | /// Allocates more memory as necessary. |
| 273 | /// Invalidates pointers if additional memory is needed. |
| 267 | 274 | pub fn appendNTimes(self: *Self, value: T, n: usize) Allocator.Error!void { |
| 268 | 275 | const old_len = self.items.len; |
| 269 | 276 | try self.resize(self.items.len + n); |
| ... | ... | @@ -281,6 +288,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 281 | 288 | |
| 282 | 289 | /// Adjust the list's length to `new_len`. |
| 283 | 290 | /// Does not initialize added items if any. |
| 291 | /// Invalidates pointers if additional memory is needed. |
| 284 | 292 | pub fn resize(self: *Self, new_len: usize) Allocator.Error!void { |
| 285 | 293 | try self.ensureTotalCapacity(new_len); |
| 286 | 294 | self.items.len = new_len; |
| ... | ... | @@ -527,6 +535,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 527 | 535 | /// Insert `item` at index `n`. Moves `list[n .. list.len]` |
| 528 | 536 | /// to higher indices to make room. |
| 529 | 537 | /// This operation is O(N). |
| 538 | /// Invalidates pointers if additional memory is needed. |
| 530 | 539 | pub fn insert(self: *Self, allocator: Allocator, n: usize, item: T) Allocator.Error!void { |
| 531 | 540 | try self.ensureUnusedCapacity(allocator, 1); |
| 532 | 541 | self.items.len += 1; |
| ... | ... | @@ -538,6 +547,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 538 | 547 | /// Insert slice `items` at index `i`. Moves `list[i .. list.len]` to |
| 539 | 548 | /// higher indicices make room. |
| 540 | 549 | /// This operation is O(N). |
| 550 | /// Invalidates pointers if additional memory is needed. |
| 541 | 551 | pub fn insertSlice(self: *Self, allocator: Allocator, i: usize, items: []const T) Allocator.Error!void { |
| 542 | 552 | try self.ensureUnusedCapacity(allocator, items.len); |
| 543 | 553 | self.items.len += items.len; |
| ... | ... | @@ -557,6 +567,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 557 | 567 | } |
| 558 | 568 | |
| 559 | 569 | /// Extend the list by 1 element. Allocates more memory as necessary. |
| 570 | /// Invalidates pointers if additional memory is needed. |
| 560 | 571 | pub fn append(self: *Self, allocator: Allocator, item: T) Allocator.Error!void { |
| 561 | 572 | const new_item_ptr = try self.addOne(allocator); |
| 562 | 573 | new_item_ptr.* = item; |
| ... | ... | @@ -598,6 +609,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 598 | 609 | |
| 599 | 610 | /// Append the slice of items to the list. Allocates more |
| 600 | 611 | /// memory as necessary. |
| 612 | /// Invalidates pointers if additional memory is needed. |
| 601 | 613 | pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) Allocator.Error!void { |
| 602 | 614 | try self.ensureUnusedCapacity(allocator, items.len); |
| 603 | 615 | self.appendSliceAssumeCapacity(items); |
| ... | ... | @@ -616,6 +628,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 616 | 628 | /// Append the slice of items to the list. Allocates more |
| 617 | 629 | /// memory as necessary. Only call this function if a call to `appendSlice` instead would |
| 618 | 630 | /// be a compile error. |
| 631 | /// Invalidates pointers if additional memory is needed. |
| 619 | 632 | pub fn appendUnalignedSlice(self: *Self, allocator: Allocator, items: []align(1) const T) Allocator.Error!void { |
| 620 | 633 | try self.ensureUnusedCapacity(allocator, items.len); |
| 621 | 634 | self.appendUnalignedSliceAssumeCapacity(items); |
| ... | ... | @@ -654,6 +667,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 654 | 667 | |
| 655 | 668 | /// Same as `append` except it returns the number of bytes written, which is always the same |
| 656 | 669 | /// as `m.len`. The purpose of this function existing is to match `std.io.Writer` API. |
| 670 | /// Invalidates pointers if additional memory is needed. |
| 657 | 671 | fn appendWrite(context: WriterContext, m: []const u8) Allocator.Error!usize { |
| 658 | 672 | try context.self.appendSlice(context.allocator, m); |
| 659 | 673 | return m.len; |
| ... | ... | @@ -661,6 +675,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 661 | 675 | |
| 662 | 676 | /// Append a value to the list `n` times. |
| 663 | 677 | /// Allocates more memory as necessary. |
| 678 | /// Invalidates pointers if additional memory is needed. |
| 664 | 679 | pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) Allocator.Error!void { |
| 665 | 680 | const old_len = self.items.len; |
| 666 | 681 | try self.resize(allocator, self.items.len + n); |
| ... | ... | @@ -679,6 +694,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 679 | 694 | |
| 680 | 695 | /// Adjust the list's length to `new_len`. |
| 681 | 696 | /// Does not initialize added items, if any. |
| 697 | /// Invalidates pointers if additional memory is needed. |
| 682 | 698 | pub fn resize(self: *Self, allocator: Allocator, new_len: usize) Allocator.Error!void { |
| 683 | 699 | try self.ensureTotalCapacity(allocator, new_len); |
| 684 | 700 | self.items.len = new_len; |