| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using Itinero.Network; |
| | | 4 | | using Itinero.Network.Tiles.Standalone.Global; |
| | | 5 | | |
| | | 6 | | namespace Itinero.Data; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// A global id set mapping global edge ids to local edge ids. |
| | | 10 | | /// </summary> |
| | | 11 | | public sealed class GlobalEdgeIdSet : IEnumerable<(GlobalEdgeId globalId, EdgeId edgeId)> |
| | | 12 | | { |
| | 15 | 13 | | private readonly Dictionary<GlobalEdgeId, EdgeId> _set = new(); |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Sets a new mapping. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="globalEdgeId">The global edge id.</param> |
| | | 19 | | /// <param name="edgeId">The local edge id.</param> |
| | | 20 | | public void Set(GlobalEdgeId globalEdgeId, EdgeId edgeId) |
| | 49 | 21 | | { |
| | 49 | 22 | | _set[globalEdgeId] = edgeId; |
| | 49 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Removes a mapping. |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="globalEdgeId">The global edge id.</param> |
| | | 29 | | public void Remove(GlobalEdgeId globalEdgeId) |
| | 0 | 30 | | { |
| | 0 | 31 | | _set.Remove(globalEdgeId); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets a mapping if it exists. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="globalEdgeId">The global edge id.</param> |
| | | 38 | | /// <param name="edgeId">The edge associated with the given global edge, if any.</param> |
| | | 39 | | /// <returns>True if a mapping exists, false otherwise.</returns> |
| | | 40 | | public bool TryGet(GlobalEdgeId globalEdgeId, out EdgeId edgeId) |
| | 127 | 41 | | { |
| | 127 | 42 | | return _set.TryGetValue(globalEdgeId, out edgeId); |
| | 127 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Returns an enumerator that iterates through the collection. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <returns>An enumerator that can be used to iterate through the collection.</returns> |
| | | 49 | | public IEnumerator<(GlobalEdgeId globalId, EdgeId edgeId)> GetEnumerator() |
| | 0 | 50 | | { |
| | 0 | 51 | | foreach (var (key, value) in _set) |
| | 0 | 52 | | { |
| | 0 | 53 | | yield return (key, value); |
| | 0 | 54 | | } |
| | 0 | 55 | | } |
| | | 56 | | |
| | | 57 | | IEnumerator IEnumerable.GetEnumerator() |
| | 0 | 58 | | { |
| | 0 | 59 | | return this.GetEnumerator(); |
| | 0 | 60 | | } |
| | | 61 | | } |