< Summary

Information
Class: MoreStructures.SuffixStructures.SuffixStructureTreePathExtensions
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/SuffixStructures/SuffixStructureTreePathExtensions.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 99
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
SuffixFor(...)100%1100%
IsSuffixOf(...)100%1100%
ContainsIndex(...)100%2100%
ContainsIndexesNonBiggerThan(...)100%2100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/SuffixStructures/SuffixStructureTreePathExtensions.cs

#LineLine coverage
 1using MoreStructures.RecImmTrees;
 2using MoreStructures.Utilities;
 3
 4namespace MoreStructures.SuffixStructures;
 5
 6/// <summary>
 7/// Extension methods for all <see cref="TreePath{TEdge, TNode}"/> used in
 8/// <see cref="ISuffixStructureNode{TEdge, TNode}"/> structures.
 9/// </summary>
 10public static class SuffixStructureTreePathExtensions
 11{
 12    /// <summary>
 13    /// Calculate the suffix corresponding to this path on the provided terminator-including text.
 14    /// </summary>
 15    /// <typeparam name="TEdge">
 16    ///     <inheritdoc cref="ISuffixStructureEdge{TEdge, TNode}" path="/typeparam[@name='TEdge']"/>
 17    /// </typeparam>
 18    /// <typeparam name="TNode">
 19    ///     <inheritdoc cref="ISuffixStructureNode{TEdge, TNode}" path="/typeparam[@name='TNode']"/>
 20    /// </typeparam>
 21    /// <param name="path">The path to traverse to build the suffix.</param>
 22    /// <param name="text">The text, including the terminator character.</param>
 23    /// <returns>A <see cref="IValueEnumerable{T}"/> sequence of <see cref="char"/> containing the suffix.</returns>
 24    public static IValueEnumerable<char> SuffixFor<TEdge, TNode>(
 25        this TreePath<TEdge, TNode> path,
 26        TextWithTerminator text)
 27        where TEdge : IRecImmDictIndexedTreeEdge<TEdge, TNode>, TextWithTerminator.ISelector
 28        where TNode : IRecImmDictIndexedTreeNode<TEdge, TNode> =>
 29
 14430        path.PathNodes
 93631            .SelectMany(node => text[node.Key])
 14432            .AsValue();
 33
 34    /// <summary>
 35    /// Whether this path identifies a suffix of the provided text.
 36    /// </summary>
 37    /// <typeparam name="TEdge">
 38    ///     <inheritdoc cref="ISuffixStructureEdge{TEdge, TNode}" path="/typeparam[@name='TEdge']"/>
 39    /// </typeparam>
 40    /// <typeparam name="TNode">
 41    ///     <inheritdoc cref="ISuffixStructureNode{TEdge, TNode}" path="/typeparam[@name='TNode']"/>
 42    /// </typeparam>
 43    /// <param name="path">The path, identifying a segment of the provided text.</param>
 44    /// <param name="text">The text, including the terminator character.</param>
 45    /// <returns>True if the segment of text is also a suffix the text.</returns>
 46    public static bool IsSuffixOf<TEdge, TNode>
 47        (this TreePath<TEdge, TNode> path,
 48        TextWithTerminator text)
 49        where TEdge : IRecImmDictIndexedTreeEdge<TEdge, TNode>, TextWithTerminator.ISelector
 50        where TNode : IRecImmDictIndexedTreeNode<TEdge, TNode> =>
 51
 3552        text.EndsWith(path.SuffixFor(text));
 53
 54    /// <summary>
 55    /// Whether the provided <paramref name="path"/> includes at least once, on any node of the path, the provided
 56    /// <paramref name="index"/>.
 57    /// </summary>
 58    /// <typeparam name="TEdge">
 59    ///     <inheritdoc cref="ISuffixStructureEdge{TEdge, TNode}" path="/typeparam[@name='TEdge']"/>
 60    /// </typeparam>
 61    /// <typeparam name="TNode">
 62    ///     <inheritdoc cref="ISuffixStructureNode{TEdge, TNode}" path="/typeparam[@name='TNode']"/>
 63    /// </typeparam>
 64    /// <param name="path">The path to walk, looking for <paramref name="index"/>.</param>
 65    /// <param name="index">The index of the char of the text, to look for. Must be non-negative.</param>
 66    /// <returns>A boolean.</returns>
 67    public static bool ContainsIndex<TEdge, TNode>(
 68        this TreePath<TEdge, TNode> path,
 69        int index)
 70        where TEdge : ISuffixStructureEdge<TEdge, TNode>
 71        where TNode : ISuffixStructureNode<TEdge, TNode> =>
 72
 57773        index >= 0
 141474            ? path.PathNodes.Any(pathNode => pathNode.Key.ContainsIndex(index))
 57775            : throw new ArgumentOutOfRangeException(nameof(index), "Must be non-negative.");
 76
 77    /// <summary>
 78    /// Whether the provided <paramref name="path"/> has at least a node starting at a index lower or equal than the
 79    /// provided <paramref name="index"/>.
 80    /// </summary>
 81    /// <typeparam name="TEdge">
 82    ///     <inheritdoc cref="ISuffixStructureEdge{TEdge, TNode}" path="/typeparam[@name='TEdge']"/>
 83    /// </typeparam>
 84    /// <typeparam name="TNode">
 85    ///     <inheritdoc cref="ISuffixStructureNode{TEdge, TNode}" path="/typeparam[@name='TNode']"/>
 86    /// </typeparam>
 87    /// <param name="path">The path to walk, looking for <paramref name="index"/>.</param>
 88    /// <param name="index">The index of the char of the text, to look for. Must be non-negative.</param>
 89    /// <returns>A boolean.</returns>
 90    public static bool ContainsIndexesNonBiggerThan<TEdge, TNode>(
 91        this TreePath<TEdge, TNode> path,
 92        int index)
 93        where TEdge : ISuffixStructureEdge<TEdge, TNode>
 94        where TNode : ISuffixStructureNode<TEdge, TNode> =>
 95
 1396        index >= 0
 1597            ? path.PathNodes.Any(pathNode => pathNode.Key.ContainsIndexesNonBiggerThan(index))
 1398            : throw new ArgumentOutOfRangeException(nameof(index), "Must be non-negative.");
 99}