< Summary

Information
Class: Trailblazer.Pathing.NavigationConnectionOwnerKeySet
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Graph/NavigationConnectionOwnerKeySet.cs
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 77
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%
Add(...)100%88100%
GetAt(...)100%22100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// NavigationConnectionOwnerKeySet.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 explicit-connection owner keys.</summary>
 11internal sealed class NavigationConnectionOwnerKeySet
 12{
 13    private readonly PersistentStringMap<PersistentStringMap<bool>> _maps;
 14    private readonly long _innerBytes;
 15    private readonly int _innerPages;
 16
 438817    private NavigationConnectionOwnerKeySet(
 438818        PersistentStringMap<PersistentStringMap<bool>> maps,
 438819        int count,
 438820        long innerBytes,
 438821        int innerPages)
 22    {
 438823        _maps = maps;
 438824        Count = count;
 438825        _innerBytes = innerBytes;
 438826        _innerPages = innerPages;
 438827    }
 28
 29    internal static NavigationConnectionOwnerKeySet Empty { get; } = new(
 30        PersistentStringMap<PersistentStringMap<bool>>.Empty,
 31        0,
 32        0,
 33        0);
 34
 35    internal int Count { get; }
 36
 2193537    internal long RetainedBytes => checked(40L + _maps.RetainedBytes + _innerBytes);
 38
 2193539    internal int PersistentPageCount => checked(
 2193540        1 + _maps.PersistentNodeCount + _innerPages);
 41
 42    internal NavigationConnectionOwnerKeySet Add(NavigationConnectionOwnerKey owner)
 43    {
 439544        bool hadMap = _maps.TryGetValue(owner.MapId, out PersistentStringMap<bool> values);
 439545        values ??= PersistentStringMap<bool>.Empty;
 439546        if (values.ContainsKey(owner.ConnectionId))
 847            return this;
 438748        long innerBytes = _innerBytes - (hadMap ? values.RetainedBytes : 0L);
 438749        int innerPages = _innerPages - (hadMap ? values.PersistentNodeCount : 0);
 438750        values = values.Set(owner.ConnectionId, true);
 438751        return new NavigationConnectionOwnerKeySet(
 438752            _maps.Set(owner.MapId, values),
 438753            checked(Count + 1),
 438754            checked(innerBytes + values.RetainedBytes),
 438755            checked(innerPages + values.PersistentNodeCount));
 56    }
 57
 58    internal NavigationConnectionOwnerKey GetAt(int ordinal)
 59    {
 1716260        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 1716261            (uint)ordinal >= (uint)Count,
 1716262            ordinal,
 1716263            nameof(ordinal));
 1716264        int remaining = ordinal;
 1752465        for (int map = 0; ; map++)
 66        {
 1752467            PersistentStringMap<bool> values = _maps.GetValueAt(map);
 1752468            if (remaining < values.Count)
 69            {
 1716270                return new NavigationConnectionOwnerKey(
 1716271                    _maps.GetKeyAt(map),
 1716272                    values.GetKeyAt(remaining));
 73            }
 36274            remaining -= values.Count;
 75        }
 76    }
 77}