< Summary

Class:Itinero.Routing.Flavours.Dijkstra.PathTreeExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/PathTreeExtensions.cs
Covered lines:30
Uncovered lines:21
Coverable lines:51
Total lines:145
Line coverage:58.8% (30 of 51)
Covered branches:12
Total branches:16
Branch coverage:75% (12 of 16)
Tag:263_26948838820

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
AddVisit(...)100%10%
AddVisit(...)100%8100%
AddVisit(...)100%10%
AddVisit(...)100%1100%
GetVisit(...)100%2100%
GetVisitWithState(...)100%2100%
GetPreviousEdges()0%20%
GetPathDebug()0%20%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using Itinero.Network;
 3using Itinero.Network.Enumerators.Edges;
 4using Itinero.Routing.DataStructures;
 5
 6namespace Itinero.Routing.Flavours.Dijkstra;
 7
 8internal static class PathTreeExtensions
 9{
 10    // TODO: this can all be represented much more compact.
 11
 12    // data6 bit layout:
 13    //   bit 0 = forward
 14    //   bit 1 = leftMain (state-bit for access-aware edge-based Dijkstra)
 15    //   bit 2 = localAccess
 16    // Backward-compat: callers that don't track state-bits pack only bit 0,
 17    // so the existing GetVisit forward read continues to work via the mask.
 18    private const uint ForwardBit = 1U;
 19    private const uint LeftMainBit = 2U;
 20    private const uint LocalAccessBit = 4U;
 21
 22    /// <summary>
 23    /// Adds a new visit the path tree.
 24    /// </summary>
 25    /// <param name="tree">The tree.</param>
 26    /// <param name="vertex">The vertex.</param>
 27    /// <param name="edge">The edge.</param>
 28    /// <param name="forward">The edge direction.</param>
 29    /// <param name="head">The head index.</param>
 30    /// <param name="previousPointer">The pointer to the previous entry.</param>
 31    /// <returns>A pointer to the visit.</returns>
 32    public static uint AddVisit(this PathTree tree, VertexId vertex, EdgeId edge, bool forward, byte? head,
 33        uint previousPointer)
 034        => AddVisit(tree, vertex, edge, forward, leftMain: false, localAccess: false, head, previousPointer);
 35
 36    /// <summary>
 37    /// Access-aware overload. Packs the <paramref name="leftMain"/> and
 38    /// <paramref name="localAccess"/> state-bits alongside the direction so the
 39    /// edge-based Dijkstra can recover them O(1) on pop.
 40    /// </summary>
 41    public static uint AddVisit(this PathTree tree, VertexId vertex, EdgeId edge, bool forward,
 42        bool leftMain, bool localAccess, byte? head, uint previousPointer)
 41441543    {
 41441544        var data0 = vertex.TileId;
 41441545        var data1 = vertex.LocalId;
 41441546        var data2 = edge.TileId;
 41441547        var data3 = edge.LocalId;
 41441548        var data4 = head ?? uint.MaxValue;
 41441549        var data5 = previousPointer;
 41441550        var data6 = (forward ? ForwardBit : 0U)
 41441551                  | (leftMain ? LeftMainBit : 0U)
 41441552                  | (localAccess ? LocalAccessBit : 0U);
 53
 41441554        return tree.Add(data0, data1, data2, data3, data4, data5, data6);
 41441555    }
 56
 57    /// <summary>
 58    /// Adds a new visit to the path tree.
 59    /// </summary>
 60    /// <param name="tree">The tree.</param>
 61    /// <param name="enumerator">The current edge.</param>
 62    /// <param name="previousPointer">The pointer to the previous entry.</param>
 63    /// <returns>A pointer to the visit.</returns>
 64    public static uint AddVisit(this PathTree tree, RoutingNetworkEdgeEnumerator enumerator, uint previousPointer)
 065    {
 066        return tree.AddVisit(enumerator.Head, enumerator.EdgeId, enumerator.Forward, enumerator.HeadOrder,
 067            previousPointer);
 068    }
 69
 70    /// <summary>
 71    /// Access-aware overload of <see cref="AddVisit(PathTree, RoutingNetworkEdgeEnumerator, uint)"/>.
 72    /// </summary>
 73    public static uint AddVisit(this PathTree tree, RoutingNetworkEdgeEnumerator enumerator,
 74        bool leftMain, bool localAccess, uint previousPointer)
 41441575    {
 41441576        return tree.AddVisit(enumerator.Head, enumerator.EdgeId, enumerator.Forward,
 41441577            leftMain, localAccess, enumerator.HeadOrder, previousPointer);
 41441578    }
 79
 80    /// <summary>
 81    /// Gets the visit at the given location.
 82    /// </summary>
 83    /// <param name="tree">The tree.</param>
 84    /// <param name="pointer">The pointer.</param>
 85    /// <returns>The visit.</returns>
 86    public static (VertexId vertex, EdgeId edge, bool forward, byte? head, uint previousPointer) GetVisit(this PathTree 
 87        uint pointer)
 126018488    {
 126018489        tree.Get(pointer, out var data0, out var data1, out var data2, out var data3, out var data4, out var data5, out 
 90
 126018491        var head = data4 == uint.MaxValue ? null : (byte?)data4;
 92
 126018493        return (new VertexId(data0, data1), new EdgeId(data2, data3), (data6 & ForwardBit) != 0, head, data5);
 126018494    }
 95
 96    /// <summary>
 97    /// Access-aware overload of <see cref="GetVisit"/> that also returns the
 98    /// packed <c>leftMain</c> and <c>localAccess</c> state-bits.
 99    /// </summary>
 100    public static (VertexId vertex, EdgeId edge, bool forward, bool leftMain, bool localAccess, byte? head, uint previou
 101        GetVisitWithState(this PathTree tree, uint pointer)
 305908102    {
 305908103        tree.Get(pointer, out var data0, out var data1, out var data2, out var data3, out var data4, out var data5, out 
 104
 305908105        var head = data4 == uint.MaxValue ? null : (byte?)data4;
 106
 305908107        return (new VertexId(data0, data1), new EdgeId(data2, data3),
 305908108            (data6 & ForwardBit) != 0,
 305908109            (data6 & LeftMainBit) != 0,
 305908110            (data6 & LocalAccessBit) != 0,
 305908111            head, data5);
 305908112    }
 113
 114    /// <summary>
 115    /// Enumerates the edges backwards from the visit at the given pointer.
 116    /// </summary>
 117    /// <param name="tree">The tree.</param>
 118    /// <param name="pointer">The pointer.</param>
 119    /// <returns>The edges and their turn.</returns>
 120    public static IEnumerable<(EdgeId edge, byte? turn)> GetPreviousEdges(this PathTree tree, uint pointer)
 0121    {
 0122        while (pointer != uint.MaxValue)
 0123        {
 0124            var (_, edge, _, head, next) = tree.GetVisit(pointer);
 125
 0126            yield return (edge, head);
 127
 0128            pointer = next;
 0129        }
 0130    }
 131
 132#if DEBUG
 133    public static IEnumerable<(EdgeId edge, bool forward, byte? turn)> GetPathDebug(this PathTree tree, uint pointer)
 0134    {
 0135        while (pointer != uint.MaxValue)
 0136        {
 0137            var (_, edge, forward, head, next) = tree.GetVisit(pointer);
 138
 0139            yield return (edge, forward, head);
 140
 0141            pointer = next;
 0142        }
 0143    }
 144#endif
 145}