< Summary

Class:Itinero.Routing.Flavours.Dijkstra.PreviousEdgeEnumerable
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/PreviousEdgeEnumerable.cs
Covered lines:20
Uncovered lines:4
Coverable lines:24
Total lines:71
Line coverage:83.3% (20 of 24)
Covered branches:6
Total branches:6
Branch coverage:100% (6 of 6)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_IsEmpty()100%2100%
GetEnumerator()100%10%
System.Collections.Generic.IEnumerable<System.ValueTuple<Itinero.Network.EdgeId,System.Byte?>>.GetEnumerator()100%1100%
System.Collections.IEnumerable.GetEnumerator()100%10%
.ctor(...)100%1100%
get_Current()100%1100%
System.Collections.IEnumerator.get_Current()100%10%
MoveNext()100%4100%
Reset()100%10%
Dispose()100%1100%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/PreviousEdgeEnumerable.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using Itinero.Network;
 4using Itinero.Routing.DataStructures;
 5
 6namespace Itinero.Routing.Flavours.Dijkstra;
 7
 8/// <summary>
 9/// A lazy, struct-based enumerable over previous edges in a path tree.
 10/// Creating this struct is allocation-free. An enumerator is only allocated
 11/// when iterated through the IEnumerable interface (e.g., when passed to ICostFunction).
 12/// When iterated via foreach on the concrete type, the struct enumerator avoids boxing.
 13/// </summary>
 14internal readonly struct PreviousEdgeEnumerable : IEnumerable<(EdgeId edge, byte? turn)>
 15{
 16    private readonly PathTree? _tree;
 17    private readonly uint _pointer;
 18
 19    public PreviousEdgeEnumerable(PathTree tree, uint pointer)
 54253020    {
 54253021        _tree = tree;
 54253022        _pointer = pointer;
 54253023    }
 24
 25    /// <summary>
 26    /// Returns true if there are no previous edges.
 27    /// </summary>
 94406028    public bool IsEmpty => _tree == null || _pointer == uint.MaxValue;
 29
 30    /// <summary>
 31    /// Returns a struct enumerator (no allocation when used via foreach on the concrete type).
 32    /// </summary>
 033    public Enumerator GetEnumerator() => new(_tree, _pointer);
 34
 35    IEnumerator<(EdgeId edge, byte? turn)> IEnumerable<(EdgeId edge, byte? turn)>.GetEnumerator() =>
 54252936        new Enumerator(_tree, _pointer);
 37
 038    IEnumerator IEnumerable.GetEnumerator() => new Enumerator(_tree, _pointer);
 39
 40    public struct Enumerator : IEnumerator<(EdgeId edge, byte? turn)>
 41    {
 42        private readonly PathTree? _tree;
 43        private uint _pointer;
 44        private (EdgeId edge, byte? turn) _current;
 45
 46        internal Enumerator(PathTree? tree, uint pointer)
 54252947        {
 54252948            _tree = tree;
 54252949            _pointer = pointer;
 54252950            _current = default;
 54252951        }
 52
 54250453        public (EdgeId edge, byte? turn) Current => _current;
 54
 055        object IEnumerator.Current => _current;
 56
 57        public bool MoveNext()
 54252958        {
 54255459            if (_tree == null || _pointer == uint.MaxValue) return false;
 60
 54250461            var (_, edge, _, head, next) = PathTreeExtensions.GetVisit(_tree, _pointer);
 54250462            _current = (edge, head);
 54250463            _pointer = next;
 54250464            return true;
 54252965        }
 66
 067        public void Reset() { }
 68
 108505869        public void Dispose() { }
 70    }
 71}