< Summary

Information
Class: MoreStructures.BurrowsWheelerTransform.Builders.LastFirstFinders.BinarySearchFinder
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/BurrowsWheelerTransform/Builders/LastFirstFinders/BinarySearchFinder.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 70
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_OrderedAscListSearch()100%1100%
.ctor(...)100%1100%
FindIndexOfNthOccurrenceInSortedBWT(...)100%4100%
FindOccurrenceRankOfCharInSortedBWT(...)100%4100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/BurrowsWheelerTransform/Builders/LastFirstFinders/BinarySearchFinder.cs

#LineLine coverage
 1namespace MoreStructures.BurrowsWheelerTransform.Builders.LastFirstFinders;
 2
 3/// <summary>
 4/// A <see cref="NaiveFinder"/> refinement which iterates over <see cref="ILastFirstFinder.BWT"/> and uses
 5/// binary search on <see cref="ILastFirstFinder.SortedBWT"/>, taking advantage of the fact that it is sorted.
 6/// </summary>
 7/// <remarks>
 8///     <para id="complexity">
 9///     COMPLEXITY
 10///     <br/>
 11///     - Search over <see cref="ILastFirstFinder.BWT"/> has Time Complexity = O(n), as it is not sorted and there's
 12///       nothing better than a linear scan without precomputing additional structures helping the search.
 13///       <br/>
 14///     - Search over <see cref="ILastFirstFinder.SortedBWT"/> has Time Complexity O(log(n)), as it is sorted and
 15///       binary search can be applied.
 16///       <br/>
 17///     - Space Complexity = O(1) for both search operations, as no additional structure is precomputed and/or stored.
 18///     </para>
 19/// </remarks>
 20public class BinarySearchFinder : NaiveFinder
 21{
 22    /// <summary>
 23    /// The <see cref="Lists.Searching.ISearch"/> implementation to be used when searching for items in lists sorted
 24    /// in ascending order.
 25    /// </summary>
 23126    protected static Lists.Searching.ISearch OrderedAscListSearch { get; } = new Lists.Searching.BinarySearch();
 27
 28    /// <inheritdoc path="//*[not(self::remarks)]"/>
 29    /// <remarks>
 30    /// <inheritdoc cref="BinarySearchFinder" path="/summary"/>
 31    /// </remarks>
 32    public BinarySearchFinder(RotatedTextWithTerminator lastBWMColumn, RotatedTextWithTerminator firstBWMColumn)
 10533        : base(lastBWMColumn, firstBWMColumn)
 10534    {
 10535    }
 36
 37    /// <inheritdoc path="//*[not(self::remarks)]"/>
 38    /// <remarks>
 39    /// This implementation takes advantage of the fact that <see cref="ILastFirstFinder.SortedBWT"/> is sorted.
 40    /// <br/>
 41    /// Time Complexity = O(log(n)). Space Complexity = O(1).
 42    /// </remarks>
 43    public override int FindIndexOfNthOccurrenceInSortedBWT(int indexOfCharInBWT, int occurrenceRank)
 21944    {
 21945        if (occurrenceRank < 0)
 346            throw new ArgumentOutOfRangeException(nameof(occurrenceRank), $"Must be non-negative: {occurrenceRank}.");
 47
 21648        var index = OrderedAscListSearch.Nth(SortedBWT, BWT[indexOfCharInBWT], occurrenceRank, CharComparer);
 49
 21550        if (index < 0)
 351            throw new ArgumentOutOfRangeException(nameof(occurrenceRank), $"Invalid value: {occurrenceRank}.");
 21252        return index;
 21253    }
 54
 55    /// <inheritdoc path="//*[not(self::remarks)]"/>
 56    /// <remarks>
 57    /// This implementation takes advantage of the fact that <see cref="ILastFirstFinder.SortedBWT"/> is sorted.
 58    /// <br/>
 59    /// Time Complexity = O(log(n)). Space Complexity = O(1).
 60    /// </remarks>
 61    public override int FindOccurrenceRankOfCharInSortedBWT(int indexOfCharInSortedBWT)
 962    {
 963        if (indexOfCharInSortedBWT < 0 || indexOfCharInSortedBWT >= SortedBWT.Length)
 264            throw new ArgumentOutOfRangeException(
 265                nameof(indexOfCharInSortedBWT), $"Invalid value: {indexOfCharInSortedBWT}");
 66
 767        return indexOfCharInSortedBWT - OrderedAscListSearch.First(
 768            SortedBWT, SortedBWT[indexOfCharInSortedBWT], CharComparer, 0, indexOfCharInSortedBWT);
 769    }
 70}