< Summary

Information
Class: Trailblazer.Pathing.NavigationPageStampSet
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/AStar/NavigationPageStampSet.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 73
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%22100%
Reset()100%11100%
Contains(...)100%11100%
Add(...)100%22100%
Find(...)100%66100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/AStar/NavigationPageStampSet.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationPageStampSet.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;
 9using SwiftCollections.Utility;
 10
 11namespace Trailblazer.Pathing;
 12
 13/// <summary>Provides fixed-capacity deterministic page-address membership.</summary>
 14internal sealed class NavigationPageStampSet
 15{
 16    private readonly string[] _mapIds;
 17    private readonly int[] _pageIndices;
 18    private readonly long[] _stamps;
 19    private readonly int _mask;
 20    private int _count;
 3463321    private long _generation = 1;
 22
 3463323    internal NavigationPageStampSet(int capacity)
 24    {
 3463325        int required = checked(capacity * 2);
 3463326        int tableSize = 1;
 37211927        while (tableSize < required)
 33748628            tableSize = checked(tableSize * 2);
 3463329        _mapIds = new string[tableSize];
 3463330        _pageIndices = new int[tableSize];
 3463331        _stamps = new long[tableSize];
 3463332        _mask = tableSize - 1;
 3463333    }
 34
 35    internal void Reset()
 36    {
 37        unchecked
 38        {
 846639            _generation++;
 40        }
 846641        _count = 0;
 846642    }
 43
 44    internal bool Contains(string mapId, int pageIndex) =>
 165245        Find(mapId, pageIndex, out _);
 46
 47    internal bool Add(string mapId, int pageIndex)
 48    {
 4734349        if (Find(mapId, pageIndex, out int index))
 4353550            return false;
 380851        _mapIds[index] = mapId;
 380852        _pageIndices[index] = pageIndex;
 380853        _stamps[index] = _generation;
 380854        _count++;
 380855        return true;
 56    }
 57
 58    private bool Find(string mapId, int pageIndex, out int index)
 59    {
 4899560        int mapHash = SwiftHashTools.GetDeterministicStringEqualityComparer().GetHashCode(mapId);
 4899561        index = SwiftHashTools.CombineHashCodes(mapHash, pageIndex) & _mask;
 4902362        while (_stamps[index] == _generation)
 63        {
 4518864            if (_pageIndices[index] == pageIndex
 4518865                && string.Equals(_mapIds[index], mapId, StringComparison.Ordinal))
 66            {
 4516067                return true;
 68            }
 2869            index = (index + 1) & _mask;
 70        }
 383571        return false;
 72    }
 73}