< Summary

Information
Class: MoreStructures.BurrowsWheelerTransform.BWTransform
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/BurrowsWheelerTransform/BWTransform.cs
Line coverage
100%
Covered lines: 48
Uncovered lines: 0
Coverable lines: 48
Total lines: 64
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
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%2100%
get_Length()100%1100%

File(s)

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

#LineLine coverage
 1using MoreStructures.Utilities;
 2
 3namespace MoreStructures.BurrowsWheelerTransform;
 4
 5/// <summary>
 6/// The Burrows-Wheeler Transform (BWT) of a <see cref="TextWithTerminator"/> <paramref name="Text"/> is a permutation
 7/// of the chars of <paramref name="Text"/> which corresponds to the <see cref="BWMatrix.LastColumn"/> of the
 8/// <see cref="BWMatrix"/> of <paramref name="Text"/>.
 9/// </summary>
 10/// <param name="Text">The text to calculate the BWT of.</param>
 11/// <param name="Content">The string which corresponds to the transform of the text.</param>
 12/// <remarks>
 13/// This <see langword="record"/> is a typed wrapped of the underlying <see langword="string"/> representing the BWT.
 14/// It guarantes immutability and strong typing, and also keeps together the <see cref="Text"/> and its transform
 15/// <see cref="Content"/>.
 16/// </remarks>
 387917public record BWTransform(TextWithTerminator Text, RotatedTextWithTerminator Content)
 102918{
 102919    /// <summary>
 102920    /// Any strategy to sort the <see cref="char"/> of a <see cref="RotatedTextWithTerminator"/>, for example to turn
 102921    /// a BWT into its sorted version.
 102922    /// </summary>
 102923    /// <param name="text">The text to be sorted.</param>
 102924    /// <param name="comparer">
 102925    /// The <see cref="IComparer{T}"/> of <see cref="char"/> to be used for comparison.
 102926    /// If not specified, a <see cref="CharOrTerminatorComparer"/> using the
 102927    /// <see cref="RotatedTextWithTerminator.Terminator"/> of <paramref name="text" /> is used instead.
 102928    /// </param>
 102929    /// <returns>
 102930    /// A new <see cref="RotatedTextWithTerminator"/>, sorted according to the provided <paramref name="comparer"/>,
 102931    /// together with a <see cref="IEnumerable{T}"/> of <see cref="int"/>, defining the mapping of the index of each
 102932    /// char of the input text into the index of that char in the sorted version of the text.
 102933    /// </returns>
 102934    public delegate (RotatedTextWithTerminator sortedText, IEnumerable<int> indexesMapping) SortStrategy(
 102935        RotatedTextWithTerminator text, IComparer<char>? comparer = null);
 102936
 102937    /// <summary>
 102938    /// A strategy to sort a <see cref="RotatedTextWithTerminator"/> using
 102939    /// <see cref="Enumerable.OrderBy{TSource, TKey}(IEnumerable{TSource}, Func{TSource, TKey}, IComparer{TKey}?)"/>,
 102940    /// which in turn uses a QuickSort with Time Complexity = O(n * log(n)) in average and O(n^2) in the worst
 102941    /// (unlikely) case.
 102942    /// </summary>
 102943    /// <remarks>
 102944    /// Tipically used to sort the Burrows-Wheeler Transform.
 102945    /// </remarks>
 146    public static readonly SortStrategy QuickSort =
 147        (text, charComparer) =>
 20048        {
 20049            charComparer ??= CharOrTerminatorComparer.Build(text.Terminator);
 150
 7722051            var textWithIndexes = text.Select((c, i) => (c, i));
 7722052            var sortedTextWithIndexes = textWithIndexes.OrderBy(charAndIndex => charAndIndex.c, charComparer);
 20053            var sortedText = new RotatedTextWithTerminator(
 3810754                sortedTextWithIndexes.Select(charAndIndex => charAndIndex.c),
 20055                text.Terminator);
 21556            var indexesMapping = sortedTextWithIndexes.Select(charAndIndex => charAndIndex.i);
 20057            return (sortedText, indexesMapping);
 20158        };
 102959
 102960    /// <summary>
 102961    /// The length of this transform, which corresponds to the length of <see cref="Content"/>.
 102962    /// </summary>
 2263    public int Length => Content.Length;
 102964}