< Summary

Information
Class: Trailblazer.Pathing.NavigationCellAddressSet
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/NavigationCellAddressSet.cs
Line coverage
100%
Covered lines: 41
Uncovered lines: 0
Coverable lines: 41
Total lines: 83
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_RetainedBytes()100%11100%
get_PersistentPageCount()100%11100%
Contains(...)100%22100%
Add(...)100%88100%
GetAt(...)100%22100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/NavigationCellAddressSet.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationCellAddressSet.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8namespace Trailblazer.Pathing;
 9
 10/// <summary>Stores a persistent canonical set of exact navigation-cell addresses.</summary>
 11internal sealed class NavigationCellAddressSet
 12{
 13    private readonly PersistentStringMap<PersistentVoxelIndexMap<byte>> _maps;
 14    private readonly long _innerBytes;
 15    private readonly int _innerPages;
 16
 4082117    private NavigationCellAddressSet(
 4082118        PersistentStringMap<PersistentVoxelIndexMap<byte>> maps,
 4082119        int count,
 4082120        long innerBytes,
 4082121        int innerPages)
 22    {
 4082123        _maps = maps;
 4082124        Count = count;
 4082125        _innerBytes = innerBytes;
 4082126        _innerPages = innerPages;
 4082127    }
 28
 29    internal static NavigationCellAddressSet Empty { get; } = new(
 30        PersistentStringMap<PersistentVoxelIndexMap<byte>>.Empty,
 31        0,
 32        0,
 33        0);
 34
 35    internal int Count { get; }
 36
 39575937    internal long RetainedBytes => checked(40L + _maps.RetainedBytes + _innerBytes);
 38
 39612739    internal int PersistentPageCount => checked(
 39612740        1 + _maps.PersistentNodeCount + _innerPages);
 41
 42    internal bool Contains(NavigationCellAddress address) =>
 1863143        _maps.TryGetValue(address.MapId, out PersistentVoxelIndexMap<byte> values)
 1863144        && values.TryGetValue(address.Index, out _);
 45
 46    internal NavigationCellAddressSet Add(NavigationCellAddress address)
 47    {
 4565948        bool hadMap = _maps.TryGetValue(
 4565949            address.MapId,
 4565950            out PersistentVoxelIndexMap<byte> values);
 4565951        values ??= PersistentVoxelIndexMap<byte>.Empty;
 4565952        if (values.TryGetValue(address.Index, out _))
 483953            return this;
 4082054        long innerBytes = _innerBytes - (hadMap ? values.RetainedBytes : 0L);
 4082055        int innerPages = _innerPages - (hadMap ? values.PersistentNodeCount : 0);
 4082056        values = values.Set(address.Index, 1);
 4082057        return new NavigationCellAddressSet(
 4082058            _maps.Set(address.MapId, values),
 4082059            checked(Count + 1),
 4082060            checked(innerBytes + values.RetainedBytes),
 4082061            checked(innerPages + values.PersistentNodeCount));
 62    }
 63
 64    internal NavigationCellAddress GetAt(int ordinal)
 65    {
 7628266        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 7628267            (uint)ordinal >= (uint)Count,
 7628268            ordinal,
 7628269            nameof(ordinal));
 7628270        int remaining = ordinal;
 7826171        for (int map = 0; ; map++)
 72        {
 7826173            PersistentVoxelIndexMap<byte> values = _maps.GetValueAt(map);
 7826174            if (remaining < values.Count)
 75            {
 7628276                return new NavigationCellAddress(
 7628277                    _maps.GetKeyAt(map),
 7628278                    values.GetKeyAt(remaining));
 79            }
 197980            remaining -= values.Count;
 81        }
 82    }
 83}