< Summary

Class:Itinero.Network.Search.Islands.Islands
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/Search/Islands/Islands.cs
Covered lines:0
Uncovered lines:57
Coverable lines:57
Total lines:124
Line coverage:0% (0 of 57)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%10%
.ctor(...)100%10%
SetTileDone(...)100%10%
GetTileDone(...)100%10%
IsEdgeOnIsland(...)100%10%
SetEdgeOnIsland(...)100%10%
Clone()0%40%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/Search/Islands/Islands.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Threading;
 3
 4namespace Itinero.Network.Search.Islands;
 5
 6internal class Islands
 7{
 8    private readonly HashSet<uint> _tiles; // holds the tiles that have been processed.
 09    private readonly ReaderWriterLockSlim _tilesLock = new();
 10    private readonly HashSet<EdgeId> _islandEdges;
 011    private readonly ReaderWriterLockSlim _islandEdgesLock = new();
 12
 013    internal Islands()
 014    {
 015        _tiles = [];
 016        _islandEdges = [];
 017    }
 18
 019    private Islands(HashSet<uint> tiles, HashSet<EdgeId> islandEdges)
 020    {
 021        _tiles = tiles;
 022        _islandEdges = islandEdges;
 023    }
 24
 25    /// <summary>
 26    /// Sets the tile as done.
 27    /// </summary>
 28    /// <param name="tileId">Sets the tile as done.</param>
 29    /// <returns>True if the tile is done.</returns>
 30    public bool SetTileDone(uint tileId)
 031    {
 32        try
 033        {
 034            _tilesLock.EnterWriteLock();
 35
 036            return _tiles.Add(tileId);
 37        }
 38        finally
 039        {
 040            _tilesLock.ExitWriteLock();
 041        }
 042    }
 43
 44    /// <summary>
 45    /// Returns true if the given tile is done.
 46    /// </summary>
 47    /// <param name="tileId"></param>
 48    /// <returns></returns>
 49    public bool GetTileDone(uint tileId)
 050    {
 51        try
 052        {
 053            _tilesLock.EnterReadLock();
 54
 055            return _tiles.Contains(tileId);
 56        }
 57        finally
 058        {
 059            _tilesLock.ExitReadLock();
 060        }
 061    }
 62
 63    /// <summary>
 64    /// Returns true if the given edge is on an island.
 65    /// </summary>
 66    /// <param name="edge"></param>
 67    /// <returns></returns>
 68    public bool IsEdgeOnIsland(EdgeId edge)
 069    {
 70        try
 071        {
 072            _islandEdgesLock.EnterReadLock();
 73
 074            return _islandEdges.Contains(edge);
 75        }
 76        finally
 077        {
 078            _islandEdgesLock.ExitReadLock();
 079        }
 080    }
 81
 82    /// <summary>
 83    /// Marks the given edge as on an island.
 84    /// </summary>
 85    /// <param name="edge"></param>
 86    /// <returns></returns>
 87    public bool SetEdgeOnIsland(EdgeId edge)
 088    {
 89        try
 090        {
 091            _islandEdgesLock.EnterWriteLock();
 92
 093            return _islandEdges.Add(edge);
 94        }
 95        finally
 096        {
 097            _islandEdgesLock.ExitWriteLock();
 098        }
 099    }
 100
 101    internal Islands Clone()
 0102    {
 103        try
 0104        {
 0105            _tilesLock.EnterWriteLock();
 106
 107
 108            try
 0109            {
 0110                _islandEdgesLock.EnterWriteLock();
 111
 0112                return new Islands([.. _tiles], [.. _islandEdges]);
 113            }
 114            finally
 0115            {
 0116                _islandEdgesLock.ExitWriteLock();
 0117            }
 118        }
 119        finally
 0120        {
 0121            _tilesLock.ExitWriteLock();
 0122        }
 0123    }
 124}