< Summary

Class:Itinero.IO.Osm.Collections.NodeIndex
Assembly:Itinero.IO.Osm
File(s):/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/Collections/NodeIndex.cs
Covered lines:0
Uncovered lines:69
Coverable lines:69
Total lines:140
Line coverage:0% (0 of 69)
Covered branches:0
Total branches:16
Branch coverage:0% (0 of 16)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%10%
AddId(...)0%20%
SortAndConvertIndex()100%10%
get_Item(...)0%20%
Set(...)0%20%
TryGetIndex(...)0%40%
SetIndex(...)0%20%
TryGetCoreNode(...)0%20%
TryGetValue(...)0%20%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/Collections/NodeIndex.cs

#LineLine coverage
 1namespace Itinero.IO.Osm.Collections;
 2
 3/// <summary>
 4/// A cache for node coordinates.
 5/// </summary>
 6internal sealed class NodeIndex
 7{
 8    private readonly UnsignedNodeIndex _negativeNodeIndex;
 9    private readonly UnsignedNodeIndex _positiveNodeIndex;
 10
 011    public NodeIndex()
 012    {
 013        _negativeNodeIndex = new UnsignedNodeIndex();
 014        _positiveNodeIndex = new UnsignedNodeIndex();
 015    }
 16
 17    /// <summary>
 18    /// Adds a node id to the index.
 19    /// </summary>
 20    public void AddId(long id)
 021    {
 022        if (id >= 0)
 023        {
 024            _positiveNodeIndex.AddId(id);
 025        }
 26        else
 027        {
 028            _negativeNodeIndex.AddId(-id);
 029        }
 030    }
 31
 32    /// <summary>
 33    /// Sorts and converts the index.
 34    /// </summary>
 35    public void SortAndConvertIndex()
 036    {
 037        _positiveNodeIndex.SortAndConvertIndex();
 038        _negativeNodeIndex.SortAndConvertIndex();
 039    }
 40
 41    /// <summary>
 42    /// Gets the node id at the given index.
 43    /// </summary>
 44    public long this[long idx]
 45    {
 46        get
 047        {
 048            if (idx >= _negativeNodeIndex.Count)
 049            {
 050                return _positiveNodeIndex[idx - _negativeNodeIndex.Count];
 51            }
 52
 053            return _negativeNodeIndex[idx];
 054        }
 55    }
 56
 57    /// <summary>
 58    /// Sets a vertex id for the given vertex.
 59    /// </summary>
 60    public void Set(long id, uint vertex)
 061    {
 062        if (id >= 0)
 063        {
 064            _positiveNodeIndex.Set(id, vertex);
 065        }
 66        else
 067        {
 068            _negativeNodeIndex.Set(-id, vertex);
 069        }
 070    }
 71
 72    /// <summary>
 73    /// Gets the coordinate for the given node.
 74    /// </summary>
 75    public long TryGetIndex(long id)
 076    {
 077        if (id >= 0)
 078        {
 079            return _positiveNodeIndex.TryGetIndex(id);
 80        }
 81        else
 082        {
 083            var result = _negativeNodeIndex.TryGetIndex(-id);
 084            if (result == long.MaxValue)
 085            {
 086                return long.MaxValue;
 87            }
 88
 089            return -(result + 1);
 90        }
 091    }
 92
 93    /// <summary>
 94    /// Sets the coordinate for the given index.
 95    /// </summary>
 96    public void SetIndex(long idx, float latitude, float longitude)
 097    {
 098        if (idx >= 0)
 099        {
 0100            _positiveNodeIndex.SetIndex(idx, latitude, longitude);
 0101        }
 102        else
 0103        {
 0104            idx = -idx - 1;
 0105            _negativeNodeIndex.SetIndex(idx, latitude, longitude);
 0106        }
 0107    }
 108
 109    /// <summary>
 110    /// Tries to get a core node and it's matching vertex.
 111    /// </summary>
 112    public bool TryGetCoreNode(long id, out uint vertex)
 0113    {
 0114        if (id >= 0)
 0115        {
 0116            return _positiveNodeIndex.TryGetCoreNode(id, out vertex);
 117        }
 118        else
 0119        {
 0120            return _negativeNodeIndex.TryGetCoreNode(-id, out vertex);
 121        }
 0122    }
 123
 124    /// <summary>
 125    /// Gets all relevant info on the given node.
 126    /// </summary>
 127    public bool TryGetValue(long id, out float latitude, out float longitude, out bool isCore, out uint vertex,
 128        out long idx)
 0129    {
 0130        if (id >= 0)
 0131        {
 0132            return _positiveNodeIndex.TryGetValue(id, out latitude, out longitude, out isCore, out vertex, out idx);
 133        }
 134        else
 0135        {
 0136            return _negativeNodeIndex.TryGetValue(-id, out latitude, out longitude, out isCore, out vertex,
 0137                out idx);
 138        }
 0139    }
 140}