| | 1 | | using Itinero.Profiles; |
| | 2 | |
|
| | 3 | | namespace Itinero.Routing.Costs.Caches; |
| | 4 | |
|
| | 5 | | internal class EdgeFactorCache |
| | 6 | | { |
| | 7 | | private EdgeFactor?[] _cache; |
| | 8 | |
|
| 26 | 9 | | public EdgeFactorCache() |
| 26 | 10 | | { |
| 26 | 11 | | _cache = new EdgeFactor?[1024]; |
| 26 | 12 | | } |
| | 13 | |
|
| | 14 | | public EdgeFactor? Get(uint edgeTypeId) |
| 36 | 15 | | { |
| 36 | 16 | | if (_cache.Length <= edgeTypeId) |
| 0 | 17 | | { |
| 0 | 18 | | return null; |
| | 19 | | } |
| | 20 | |
|
| 36 | 21 | | return _cache[edgeTypeId]; |
| 36 | 22 | | } |
| | 23 | |
|
| | 24 | | public void Set(uint edgeTypeId, EdgeFactor factor) |
| 26 | 25 | | { |
| 26 | 26 | | var cache = _cache; |
| 26 | 27 | | if (cache.Length <= edgeTypeId) |
| 0 | 28 | | { |
| 0 | 29 | | var newSize = _cache.Length + 1024; |
| 0 | 30 | | while (newSize <= edgeTypeId) |
| 0 | 31 | | { |
| 0 | 32 | | newSize += 1024; |
| 0 | 33 | | } |
| | 34 | |
|
| 0 | 35 | | var newCache = new EdgeFactor?[newSize]; |
| 0 | 36 | | cache.CopyTo(newCache, 0); |
| | 37 | |
|
| 0 | 38 | | newCache[edgeTypeId] = factor; |
| 0 | 39 | | _cache = newCache; |
| 0 | 40 | | return; |
| | 41 | | } |
| | 42 | |
|
| 26 | 43 | | cache[edgeTypeId] = factor; |
| 26 | 44 | | } |
| | 45 | | } |