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