| | 1 | | using System; |
| | 2 | | using Reminiscence.Arrays; |
| | 3 | |
|
| | 4 | | namespace Itinero.Network.TurnCosts; |
| | 5 | |
|
| | 6 | | internal static class OrderCoder |
| | 7 | | { |
| | 8 | | internal const int MaxOrderHeadTail = 14; |
| | 9 | |
|
| | 10 | | public static void SetTailHeadOrder(this ArrayBase<byte> data, long i, byte? tail, byte? head) |
| 296 | 11 | | { |
| 296 | 12 | | if (tail.HasValue && tail.Value > MaxOrderHeadTail) |
| 0 | 13 | | { |
| 0 | 14 | | throw new ArgumentOutOfRangeException(nameof(tail), |
| 0 | 15 | | $"Maximum order exceeded."); |
| | 16 | | } |
| | 17 | |
|
| 296 | 18 | | if (head.HasValue && head.Value > MaxOrderHeadTail) |
| 0 | 19 | | { |
| 0 | 20 | | throw new ArgumentOutOfRangeException(nameof(head), |
| 0 | 21 | | $"Maximum order exceeded."); |
| | 22 | | } |
| | 23 | |
|
| 296 | 24 | | var d = 0; |
| 296 | 25 | | if (tail.HasValue) |
| 13 | 26 | | { |
| 13 | 27 | | d = tail.Value + 1; |
| 13 | 28 | | } |
| | 29 | |
|
| 296 | 30 | | if (head.HasValue) |
| 13 | 31 | | { |
| 13 | 32 | | d += (head.Value + 1) * 16; |
| 13 | 33 | | } |
| | 34 | |
|
| 296 | 35 | | data[i] = (byte)d; |
| 296 | 36 | | } |
| | 37 | |
|
| | 38 | | public static void GetTailHeadOrder(this ArrayBase<byte> data, long i, ref byte? tail, ref byte? head) |
| 1132 | 39 | | { |
| 1132 | 40 | | tail = null; |
| 1132 | 41 | | head = null; |
| | 42 | |
|
| 1132 | 43 | | var d = data[i]; |
| 1132 | 44 | | if (d == 0) |
| 1044 | 45 | | { |
| 1044 | 46 | | return; |
| | 47 | | } |
| | 48 | |
|
| 88 | 49 | | tail = null; |
| 88 | 50 | | var t = d % 16; |
| 88 | 51 | | if (t > 0) |
| 43 | 52 | | { |
| 43 | 53 | | tail = (byte)(t - 1); |
| 43 | 54 | | } |
| | 55 | |
|
| 88 | 56 | | var h = d / 16; |
| 88 | 57 | | if (h > 0) |
| 47 | 58 | | { |
| 47 | 59 | | head = (byte)(h - 1); |
| 47 | 60 | | } |
| 1132 | 61 | | } |
| | 62 | | } |