< Summary

Information
Class: MoreStructures.BurrowsWheelerTransform.BWMatrix
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/BurrowsWheelerTransform/BWMatrix.cs
Line coverage
100%
Covered lines: 99
Uncovered lines: 0
Coverable lines: 99
Total lines: 116
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Text()100%1100%
.ctor(...)100%1100%
get_Content()100%1100%
get_Transform()100%1100%
get_FirstColumn()100%1100%
get_LastColumn()100%1100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/BurrowsWheelerTransform/BWMatrix.cs

#LineLine coverage
 1using MoreLinq;
 2using MoreStructures.Utilities;
 3
 4namespace MoreStructures.BurrowsWheelerTransform;
 5
 6/// <summary>
 7/// The Burrows-Wheeler Matrix (BWM) of a <see cref="TextWithTerminator"/> is the square matrix all cyclic rotations of
 8/// the provided <see cref="TextWithTerminator"/>, with rows sorted in ascending order and taking into account that
 9/// <see cref="TextWithTerminator.Terminator"/> is to be considered smaller than any other char in the text.
 10/// </summary>
 11/// <param name="Text">The text, corresponding to the provided BWM.</param>
 12/// <param name="Content">The content of the Burrows-Wheeler Matrix (BWM) of <see cref="Text"/>.</param>
 13/// <remarks>
 14/// This <see langword="record"/> is a typed wrapped of the underlying <see langword="IList{string}"/> representing
 15/// the BWM. It guarantes immutability and strong typing, and also keeps together the <see cref="Text"/> and its
 16/// matrix <see cref="Content"/>, providing BWM-specific functionalities.
 17/// </remarks>
 251218public record BWMatrix(TextWithTerminator Text, IList<string> Content)
 62819{
 62820    // CharOrTerminatorComparer is a record, so compared by value
 62821    private readonly IComparer<char> _charComparer = CharOrTerminatorComparer.Build(Text.Terminator);
 62822
 62823    /// <summary>
 62824    /// <inheritdoc cref="BWMatrix(TextWithTerminator, IList{string})" path="/param[@name='Content']"/>
 62825    /// </summary>
 62826    /// <returns>
 62827    /// A readonly immutable list of strings, each one containing a row of the matrix, i.e. a string containing a
 62828    /// cyclic rotation of <see cref="Text"/>.
 62829    /// </returns>
 62830    /// <example>
 62831    /// Code:
 62832    /// <code>
 62833    /// new BWTMatrix(new("ab"), new string[] { "$ab", "ab$", "b$a" }).Content
 62834    /// </code>
 62835    ///
 62836    /// Result:
 62837    /// <code>
 62838    /// {
 62839    ///     "$ab",
 62840    ///     "ab$",
 62841    ///     "b$a",
 62842    /// }
 62843    /// </code>
 62844    /// </example>
 114445    public IList<string> Content { get; init; } = Content.ToValueReadOnlyCollection();
 62846
 62847    /// <summary>
 62848    /// Builds the Burrows-Wheeler Transform from this <see cref="BWMatrix"/>, which corresponds to the last column
 62849    /// of the matrix, stored in <see cref="Content"/>.
 62850    /// </summary>
 62851    /// <returns>
 62852    /// A <see cref="BWTransform"/> object wrapping the string containing the Burrows-Wheeler transform.
 62853    /// </returns>
 62854    /// <example>
 62855    ///     Code:
 62856    ///     <code>
 62857    ///     new BWTMatrix(new("mississippi")).Transform;
 62858    ///     </code>
 62859    ///
 62860    ///     Result:
 62861    ///     <code>
 62862    ///     "ipssm$pissii"
 62863    ///     </code>
 62864    /// </example>
 62865    /// <remarks>
 62866    /// Requires <see cref="Content"/> calculation.
 62867    /// <inheritdoc cref="BWMatrix" path="/remarks/para[@id='lazy-initialization']"/>
 62868    /// </remarks>
 62869    public BWTransform Transform =>
 969070        new(Text, new(Content.Select(r => r[^1]), Text.Terminator));
 62871
 62872    /// <summary>
 62873    /// Returns the first column of this <see cref="BWMatrix"/>. Corresponds to the sorted <see cref="Text"/> and
 62874    /// also to the sorted <see cref="Transform"/> of this <see cref="BWMatrix"/>.
 62875    /// </summary>
 62876    /// <example>
 62877    ///     Code:
 62878    ///     <code>
 62879    ///     new BWTMatrix(new("mississippi")).FirstColumn
 62880    ///     </code>
 62881    ///
 62882    ///     Result:
 62883    ///     <code>
 62884    ///     "$iiiimppssss"
 62885    ///     </code>
 62886    /// </example>
 62887    /// <remarks>
 62888    /// Unlike <see cref="LastColumn"/> and <see cref="Transform"/>, <see cref="FirstColumn"/> wouldn't require
 62889    /// computation of the <see cref="Content"/> of this <see cref="BWMatrix"/>, since the <see cref="FirstColumn"/>
 62890    /// can easily be calculated by sorting the input <see cref="Text"/>.
 62891    /// </remarks>
 62892    public string FirstColumn =>
 603693        string.Concat(Text.OrderBy(c => c, _charComparer));
 62894
 62895    /// <summary>
 62896    /// Returns the last column of this <see cref="BWMatrix"/>. Corresponds to the <see cref="BWTransform.Content"/>
 62897    /// of the <see cref="Transform"/> of this <see cref="BWMatrix"/>.
 62898    /// </summary>
 62899    /// <example>
 628100    ///     Code:
 628101    ///     <code>
 628102    ///     new BWTMatrix(new("mississippi")).LastColumn
 628103    ///     </code>
 628104    ///
 628105    ///     Result:
 628106    ///     <code>
 628107    ///     "ipssm$pissii"
 628108    ///     </code>
 628109    /// </example>
 628110    /// <remarks>
 628111    /// Requires <see cref="Content"/> calculation.
 628112    /// <inheritdoc cref="BWMatrix" path="/remarks/para[@id='lazy-initialization']"/>
 628113    /// </remarks>
 628114    public string LastColumn =>
 364115        string.Concat(Transform.Content.RotatedText);
 628116}