| | 1 | | using Reminiscence.Arrays; |
| | 2 | |
|
| | 3 | | namespace Itinero.Network.Tiles; |
| | 4 | |
|
| | 5 | | internal static class ArrayBaseExtensions |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Increase the array size with a fixed step (but never more) to ensure the given position fits. |
| | 9 | | /// </summary> |
| | 10 | | /// <param name="array">The array.</param> |
| | 11 | | /// <param name="position">The position.</param> |
| | 12 | | /// <param name="step">The steps to add.</param> |
| | 13 | | /// <param name="fill">The default value to set.</param> |
| | 14 | | /// <typeparam name="T">The type of the elements in the array.</typeparam> |
| | 15 | | public static void EnsureMinimumSize<T>(this ArrayBase<T> array, long position, |
| | 16 | | long step = 16, T fill = default) |
| 1320 | 17 | | { |
| 1320 | 18 | | if (array.Length > position) |
| 719 | 19 | | { |
| 719 | 20 | | return; |
| | 21 | | } |
| | 22 | |
|
| 601 | 23 | | var increase = System.Math.DivRem(position - array.Length, step, out _) + 1; |
| 601 | 24 | | increase *= step; |
| | 25 | |
|
| 601 | 26 | | var size = array.Length; |
| 601 | 27 | | array.Resize(array.Length + increase); |
| 20428 | 28 | | for (var i = size; i < array.Length; i++) |
| 9613 | 29 | | { |
| 9613 | 30 | | array[i] = fill; |
| 9613 | 31 | | } |
| 1320 | 32 | | } |
| | 33 | | } |