| ... | ... | @@ -169,6 +169,13 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { |
| 169 | 169 | new_item_ptr.* = item; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | /// Extend the slice by 1 element, asserting the capacity is already |
| 173 | /// enough to store the new item. |
| 174 | pub fn appendAssumeCapacity(self: *Self, item: T) void { |
| 175 | const new_item_ptr = self.addOneAssumeCapacity(); |
| 176 | new_item_ptr.* = item; |
| 177 | } |
| 178 | |
| 172 | 179 | /// Remove the element at index `i`, shift elements after index |
| 173 | 180 | /// `i` forward, and return the removed element. |
| 174 | 181 | /// Asserts the slice has at least one item. |
| ... | ... | @@ -262,6 +269,10 @@ test "BoundedArray" { |
| 262 | 269 | try testing.expectEqual(a.len, 6); |
| 263 | 270 | try testing.expectEqual(a.pop(), 0xff); |
| 264 | 271 | |
| 272 | a.appendAssumeCapacity(0xff); |
| 273 | try testing.expectEqual(a.len, 6); |
| 274 | try testing.expectEqual(a.pop(), 0xff); |
| 275 | |
| 265 | 276 | try a.resize(1); |
| 266 | 277 | try testing.expectEqual(a.popOrNull(), 0); |
| 267 | 278 | try testing.expectEqual(a.popOrNull(), null); |