< 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:39
Uncovered lines:18
Coverable lines:57
Total lines:124
Line coverage:68.4% (39 of 57)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%1100%
.ctor(...)100%10%
SetTileDone(...)100%1100%
GetTileDone(...)100%1100%
IsEdgeOnIsland(...)100%1100%
SetEdgeOnIsland(...)100%1100%
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.
 99    private readonly ReaderWriterLockSlim _tilesLock = new();
 10    private readonly HashSet<EdgeId> _islandEdges;
 911    private readonly ReaderWriterLockSlim _islandEdgesLock = new();
 12
 913    internal Islands()
 914    {
 915        _tiles = [];
 916        _islandEdges = [];
 917    }
 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)
 731    {
 32        try
 733        {
 734            _tilesLock.EnterWriteLock();
 35
 736            return _tiles.Add(tileId);
 37        }
 38        finally
 739        {
 740            _tilesLock.ExitWriteLock();
 741        }
 742    }
 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)
 1650    {
 51        try
 1652        {
 1653            _tilesLock.EnterReadLock();
 54
 1655            return _tiles.Contains(tileId);
 56        }
 57        finally
 1658        {
 1659            _tilesLock.ExitReadLock();
 1660        }
 1661    }
 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)
 569669    {
 70        try
 569671        {
 569672            _islandEdgesLock.EnterReadLock();
 73
 569674            return _islandEdges.Contains(edge);
 75        }
 76        finally
 569677        {
 569678            _islandEdgesLock.ExitReadLock();
 569679        }
 569680    }
 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)
 588    {
 89        try
 590        {
 591            _islandEdgesLock.EnterWriteLock();
 92
 593            return _islandEdges.Add(edge);
 94        }
 95        finally
 596        {
 597            _islandEdgesLock.ExitWriteLock();
 598        }
 599    }
 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}