| | | 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) |
| | 1380 | 17 | | { |
| | 1380 | 18 | | if (array.Length > position) |
| | 749 | 19 | | { |
| | 749 | 20 | | return; |
| | | 21 | | } |
| | | 22 | | |
| | 631 | 23 | | var increase = System.Math.DivRem(position - array.Length, step, out _) + 1; |
| | 631 | 24 | | increase *= step; |
| | | 25 | | |
| | 631 | 26 | | var size = array.Length; |
| | 631 | 27 | | array.Resize(array.Length + increase); |
| | 21448 | 28 | | for (var i = size; i < array.Length; i++) |
| | 10093 | 29 | | { |
| | 10093 | 30 | | array[i] = fill; |
| | 10093 | 31 | | } |
| | 1380 | 32 | | } |
| | | 33 | | } |