< 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:263_26948838820

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)
 54847820    {
 54847821        _tree = tree;
 54847822        _pointer = pointer;
 54847823    }
 24
 25    /// <summary>
 26    /// Returns true if there are no previous edges.
 27    /// </summary>
 95171628    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() =>
 54843436        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)
 54843447        {
 54843448            _tree = tree;
 54843449            _pointer = pointer;
 54843450            _current = default;
 54843451        }
 52
 54842053        public (EdgeId edge, byte? turn) Current => _current;
 54
 055        object IEnumerator.Current => _current;
 56
 57        public bool MoveNext()
 54843458        {
 54844859            if (_tree == null || _pointer == uint.MaxValue) return false;
 60
 54842061            var (_, edge, _, head, next) = PathTreeExtensions.GetVisit(_tree, _pointer);
 54842062            _current = (edge, head);
 54842063            _pointer = next;
 54842064            return true;
 54843465        }
 66
 067        public void Reset() { }
 68
 109686869        public void Dispose() { }
 70    }
 71}