< Summary

Information
Class: DirectSight.Parser.Analysis.LineCoverage.DictionaryBasedLineInfo<T>
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/LineCoverage/DictionaryBasedLineInfo.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 52
Coverable lines: 52
Total lines: 124
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
GetEnumerator()0%440%
System.Collections.IEnumerable.GetEnumerator()100%110%
Resize(...)0%220%
Clone()100%110%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Parser/Analysis/LineCoverage/DictionaryBasedLineInfo.cs

#LineLine coverage
 1using System.Collections.Generic;
 2
 3namespace DirectSight.Parser.Analysis.LineCoverage;
 4
 5/// <summary>
 6/// An implementation of <see cref="ILineInfo{T}"/> that uses a dictionary to store the line information. This implement
 7/// </summary>
 8/// <typeparam name="T">The type of the elements in the line information.</typeparam>
 9internal class DictionaryBasedLineInfo<T> : ILineInfo<T>
 10{
 11    /// <summary>
 12    /// The internal dictionary that holds the line information. The keys of this dictionary represent the line indices,
 13    /// </summary>
 14    private readonly Dictionary<long, T> data;
 15
 16    /// <summary>
 17    /// The total number of elements in the line information. This value is specified in the constructor and is used to 
 18    /// </summary>
 19    private readonly long length;
 20
 21    /// <summary>
 22    /// The default value used when retrieving line information for indices that are not present in the dictionary. This
 23    /// </summary>
 24    private readonly T defaultValue;
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="DictionaryBasedLineInfo&lt;T&gt;"/> class.
 28    /// </summary>
 29    /// <param name="length">The number of elements to allocate for the internal data array. Must be non-negative.</para
 30    /// <param name="defaultValue">The default value to initialize each element with.</param>
 031    public DictionaryBasedLineInfo(long length, T defaultValue)
 032    {
 033        this.length = length;
 034        this.defaultValue = defaultValue;
 35
 036        this.data = [];
 037    }
 38
 39    /// <inheritdoc />
 40    public int Length
 41    {
 42        get
 043        {
 044            return (int)this.length;
 045        }
 46    }
 47
 48    /// <inheritdoc />
 49    public long LongLength
 50    {
 51        get
 052        {
 053            return this.length;
 054        }
 55    }
 56
 57    /// <inheritdoc />
 58    public T this[long index]
 59    {
 60        get
 061        {
 062            if (this.data.TryGetValue(index, out var value))
 063            {
 064                return value;
 65            }
 66            else
 067            {
 068                return this.defaultValue;
 69            }
 070        }
 71
 72        set
 073        {
 074            if (EqualityComparer<T>.Default.Equals(this.defaultValue, value))
 075            {
 076                this.data.Remove(index);
 077                return;
 78            }
 79
 080            this.data[index] = value;
 081        }
 82    }
 83
 84    /// <inheritdoc />
 85    public IEnumerator<T> GetEnumerator()
 086    {
 087        for (long i = 0; i < this.length; i++)
 088        {
 089            if (this.data.TryGetValue(i, out var value))
 090            {
 091                yield return value;
 092            }
 93            else
 094            {
 095                yield return this.defaultValue;
 096            }
 097        }
 098    }
 99
 100    /// <inheritdoc />
 101    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
 0102    {
 0103        return this.GetEnumerator();
 0104    }
 105
 106    /// <inheritdoc />
 107    public ILineInfo<T> Resize(long length)
 0108    {
 0109        var newLineInfo = new DictionaryBasedLineInfo<T>(length, this.defaultValue);
 110
 0111        foreach (var kv in this.data)
 0112        {
 0113            newLineInfo.data[kv.Key] = kv.Value;
 0114        }
 115
 0116        return newLineInfo;
 0117    }
 118
 119    /// <inheritdoc />
 120    public ILineInfo<T> Clone()
 0121    {
 0122        return this.Resize(this.LongLength);
 0123    }
 124}