< Summary

Information
Class: DeltaSharp.Util.Hashtable.Hashtable64
Assembly: DeltaSharp
File(s): /home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Util/Hashtable/Hashtable64.cs
Line coverage
96%
Covered lines: 30
Uncovered lines: 1
Coverable lines: 31
Total lines: 97
Line coverage: 96.7%
Branch coverage
86%
Covered branches: 26
Total branches: 30
Branch coverage: 86.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_BlockSize()100%210%
GetIndexWidth(...)100%44100%
.ctor(...)100%44100%
Match(...)100%44100%
More(...)100%44100%
Dispose()100%44100%

File(s)

/home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Util/Hashtable/Hashtable64.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Threading.Tasks;
 6
 7namespace DeltaSharp.Util.Hashtable;
 8
 9/// <summary>
 10/// Specialized hashtable to store landmarks and respective collisions
 11/// Because we hash at every 8 bytes, we can store the address as multiple of 8
 12/// To improve memory usage, there are specialized implementations according to data size
 13/// Byte-sized indices can address 255 complete 8-byte blocks, including sources
 14/// up to 2047 bytes long with a partial final block.
 15/// </summary>
 16internal readonly ref struct Hashtable64
 17{
 18    internal const int BytesPerBlock = 8;
 019    public int BlockSize => BytesPerBlock;
 20
 21    private readonly Hashtable64_8 _hashtable8;
 22    private readonly Hashtable64_16 _hashtable16;
 23#if DELTASHARP_HASHTABLE24
 24    private readonly Hashtable64_24 _hashtable24;
 25#endif
 26    private readonly Hashtable64_32 _hashtable32;
 27    private readonly byte _hashtable;
 28
 29    internal static byte GetIndexWidth(int sourceLength)
 30    {
 31        // Zero is the empty-slot sentinel; stored block indices are one-based.
 693032        if (sourceLength / BytesPerBlock <= byte.MaxValue)
 391033            return 8;
 302034        if (sourceLength < ushort.MaxValue * BytesPerBlock)
 293035            return 16;
 36#if DELTASHARP_HASHTABLE24
 4537        if (sourceLength < 0xff_ff_ff * BytesPerBlock)
 4038            return 24;
 39#endif
 5040        return 32;
 41    }
 42
 43    public Hashtable64(ReadOnlySpan<byte> data)
 44    {
 276645        _hashtable = GetIndexWidth(data.Length);
 276646        switch (_hashtable)
 47        {
 314448            case 8: _hashtable8 = new Hashtable64_8(data); break;
 234049            case 16: _hashtable16 = new Hashtable64_16(data); break;
 50#if DELTASHARP_HASHTABLE24
 2451            case 24: _hashtable24 = new Hashtable64_24(data); break;
 52#endif
 1253            default: _hashtable32 = new Hashtable64_32(data); break;
 54        }
 1255    }
 56
 57    public int Match(ReadOnlySpan<byte> data)
 58    {
 201685459        switch (_hashtable)
 60        {
 15906461            case 8: return _hashtable8.Match(data);
 148263462            case 16: return _hashtable16.Match(data);
 63#if DELTASHARP_HASHTABLE24
 18757864            case 24: return _hashtable24.Match(data);
 65#endif
 18757866            default: return _hashtable32.Match(data);
 67        }
 68    }
 69
 70    public int More(int pos)
 71    {
 10413135272        switch (_hashtable)
 73        {
 33568874            case 8: return _hashtable8.More(pos);
 10334960075            case 16: return _hashtable16.More(pos);
 76#if DELTASHARP_HASHTABLE24
 22303277            case 24: return _hashtable24.More(pos);
 78#endif
 22303279            default: return _hashtable32.More(pos);
 80        }
 81    }
 82
 83
 84
 85    public void Dispose()
 86    {
 276687        switch (_hashtable)
 88        {
 314489            case 8: _hashtable8.Dispose(); break;
 234090            case 16: _hashtable16.Dispose(); break;
 91#if DELTASHARP_HASHTABLE24
 2492            case 24: _hashtable24.Dispose(); break;
 93#endif
 1294            default: _hashtable32.Dispose(); break;
 95        }
 1296    }
 97}