2 ms·
Padding with zeroes doesn't have to involve reallocating anything--you could wrap the array in an iterator that first yields 0, then yields each array element,
by taco_emoji 8y ago
Padding with zeroes doesn't have to involve reallocating anything--you could wrap the array in an iterator that first yields 0, then yields each array element, then yields 0 again.
E.g. in C# using Linq:
foreach (var num in myArray.Prepend(0).Append(0)) { /* blah */ }