< Summary

Information
Class: Trailblazer.Pathing.NavigationAddressStampSet
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Map/Operations/NavigationAddressStampSet.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 65
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%44100%
Reset()100%11100%
Add(...)100%44100%
Contains(...)100%44100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Map/Operations/NavigationAddressStampSet.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationAddressStampSet.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
 8using System;
 9
 10namespace Trailblazer.Pathing;
 11
 12/// <summary>Provides fixed-capacity address deduplication with constant-time logical reset.</summary>
 13internal sealed class NavigationAddressStampSet
 14{
 15    private readonly NavigationCellAddress[] _values;
 16    private readonly long[] _stamps;
 17    private readonly int _mask;
 3935718    private long _generation = 1;
 19
 3935720    internal NavigationAddressStampSet(int capacity)
 21    {
 3935722        if (capacity <= 0)
 123            throw new ArgumentOutOfRangeException(nameof(capacity));
 3935624        int required = checked(capacity * 2);
 3935625        int tableSize = 1;
 39947826        while (tableSize < required)
 36012227            tableSize = checked(tableSize * 2);
 3935628        _values = new NavigationCellAddress[tableSize];
 3935629        _stamps = new long[tableSize];
 3935630        _mask = tableSize - 1;
 3935631    }
 32
 33    internal void Reset()
 34    {
 2062135        _generation = NavigationGenerationCounter.Advance(
 2062136            _generation,
 2062137            "Address stamp generation capacity is exhausted.");
 2062138    }
 39
 40    internal bool Add(NavigationCellAddress value)
 41    {
 29763942        int index = value.GetHashCode() & _mask;
 29858343        while (_stamps[index] == _generation)
 44        {
 17998145            if (_values[index].Equals(value))
 17903746                return false;
 94447            index = (index + 1) & _mask;
 48        }
 11860249        _values[index] = value;
 11860250        _stamps[index] = _generation;
 11860251        return true;
 52    }
 53
 54    internal bool Contains(NavigationCellAddress value)
 55    {
 5226856        int index = value.GetHashCode() & _mask;
 5248257        while (_stamps[index] == _generation)
 58        {
 5246559            if (_values[index].Equals(value))
 5225160                return true;
 21461            index = (index + 1) & _mask;
 62        }
 1763        return false;
 64    }
 65}