< Summary

Class:Itinero.Data.GlobalVertexIdSet
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Data/GlobalVertexIdSet.cs
Covered lines:1
Uncovered lines:18
Coverable lines:19
Total lines:65
Line coverage:5.2% (1 of 19)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%1100%
Set(...)100%10%
Remove(...)100%10%
TryGet(...)100%10%
GetEnumerator()0%20%
System.Collections.IEnumerable.GetEnumerator()100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Data/GlobalVertexIdSet.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Concurrent;
 3using System.Collections.Generic;
 4using Itinero.Network;
 5
 6namespace Itinero.Data;
 7
 8/// <summary>
 9/// Abstract definition of a global id map for vertices.
 10/// </summary>
 11public sealed class GlobalVertexIdSet : IEnumerable<(long globalId, VertexId vertex)>
 12{
 13    /// <remarks>
 14    /// Concurrent for the same reason as <see cref="GlobalEdgeIdSet"/>: written from several
 15    /// tile inserts at once.
 16    /// </remarks>
 12617    private readonly ConcurrentDictionary<long, VertexId> _set = new();
 18
 19    /// <summary>
 20    /// Sets a new mapping.
 21    /// </summary>
 22    /// <param name="globalVertexId">The global vertex id.</param>
 23    /// <param name="vertex">The local vertex.</param>
 24    public void Set(long globalVertexId, VertexId vertex)
 025    {
 026        _set[globalVertexId] = vertex;
 027    }
 28
 29    /// <summary>
 30    /// Removes a mapping.
 31    /// </summary>
 32    /// <param name="globalVertexId">The global vertex id.</param>
 33    public void Remove(long globalVertexId)
 034    {
 035        _set.TryRemove(globalVertexId, out _);
 036    }
 37
 38    /// <summary>
 39    /// Gets a mapping if it exists.
 40    /// </summary>
 41    /// <param name="globalVertexId">The global vertex id.</param>
 42    /// <param name="vertex">The vertex associated with the given global vertex, if any.</param>
 43    /// <returns>True if a mapping exists, false otherwise.</returns>
 44    public bool TryGet(long globalVertexId, out VertexId vertex)
 045    {
 046        return _set.TryGetValue(globalVertexId, out vertex);
 047    }
 48
 49    /// <summary>
 50    /// Returns an enumerator that iterates through the collection.
 51    /// </summary>
 52    /// <returns>An enumerator that can be used to iterate through the collection.</returns>
 53    public IEnumerator<(long globalId, VertexId vertex)> GetEnumerator()
 054    {
 055        foreach (var (key, value) in _set)
 056        {
 057            yield return (key, value);
 058        }
 059    }
 60
 61    IEnumerator IEnumerable.GetEnumerator()
 062    {
 063        return this.GetEnumerator();
 064    }
 65}