< Summary

Information
Class: MoreStructures.SuffixTrees.Builders.Ukkonen.MutableNode
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/SuffixTrees/Builders/Ukkonen/MutableNode.cs
Line coverage
100%
Covered lines: 54
Uncovered lines: 0
Coverable lines: 54
Total lines: 79
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
get_Id()100%1100%
.ctor(...)100%1100%
get_Children()100%1100%
get_SuffixLink()100%1100%
ToString()100%1100%
Dump(...)100%1100%
DumpR(...)100%4100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/SuffixTrees/Builders/Ukkonen/MutableNode.cs

#LineLine coverage
 1namespace MoreStructures.SuffixTrees.Builders.Ukkonen;
 2
 3/// <summary>
 4/// A node (root, internal or leaf) of the tree structure built by <see cref="UkkonenSuffixTreeBuilder"/>.
 5/// </summary>
 6/// <param name="Id">
 7/// A unique identifier of the node in the tree. Useful for debugging and tracing.
 8/// </param>
 9/// <param name="LeafStart">
 10/// The index of the character, the path from the root leading to this leaf starts with. Non-null for leaves only.
 11/// </param>
 12/// <param name="SuffixLink">
 13/// The Suffix Link associated to this node. Defined for internal nodes only.
 14/// </param>
 15/// <param name="IncomingEdge">
 16///     The <see cref="MutableEdge"/> pointing to this <see cref="MutableNode"/>. Null for the root.
 17///     Used in Rule 2 Extension, when the <see cref="IterationState.ActiveNode"/> has no <see cref="Children"/> (i.e.
 18///     it's a leaf) and no intermediate node has to be created.
 19///     <br/>
 20///     Ín such scenario, the leaf becomes parent of a new leaf, and stop having the <see cref="MutableEdge.End"/> of
 21///     its incoming <see cref="MutableEdge"/> pointing to the <see cref="IterationState.GlobalEnd"/>.
 22/// </param>
 23/// <remarks>
 24/// Mutable and having a <see cref="SuffixLink"/> to have Rule 2 Extension applied in constant time.
 25/// </remarks>
 780526internal record MutableNode(int Id, int? LeafStart, MutableNode? SuffixLink, MutableEdge? IncomingEdge = null)
 53427{
 53428    /// <summary>
 53429    /// The children of this node. Empty for leaves, non-empty for root and internal nodes.
 53430    /// </summary>
 703831    public Dictionary<MutableEdge, MutableNode> Children { get; } = new();
 53432
 53433    /// <summary>
 53434    /// <inheritdoc cref="MutableNode" path="/param[@name='SuffixLink']"/>
 53435    /// </summary>
 546336    public MutableNode? SuffixLink { get; set; } = SuffixLink;
 53437
 53438    /// <inheritdoc/>
 503739    public override string ToString() => $"{Id}";
 53440
 53441    /// <summary>
 53442    /// Settings for the <see cref="Dump(DumpParams)"/> method.
 53443    /// </summary>
 53444    /// <param name="Text">The text, on which the Ukkonen algorithm is being run.</param>
 53445    /// <param name="GlobalEnd">The global end instantiated by the <see cref="IterationState"/>.</param>
 53446    /// <param name="EdgeNodeSeparator">The string separator between pointing edge and pointed node.</param>
 53447    /// <param name="SuffixLinkSeparator">The string separator between node indicator and its suffix link.</param>
 53448    /// <param name="IndentationChar">The char to be used for indentation.</param>
 49649    public record DumpParams(
 370350        TextWithTerminator Text,
 370351        MovingEnd GlobalEnd,
 370352        string EdgeNodeSeparator = "->",
 133353        string SuffixLinkSeparator = "~>",
 419954        char IndentationChar = '\t');
 53455
 53456    /// <summary>
 53457    /// Dump the state of this node (with its entire <see cref="Children"/> structure.
 53458    /// </summary>
 53459    /// <param name="dumpParams">The parameters to be used to generate the output.</param>
 53460    /// <returns>A string showing the state of the structure under this node.</returns>
 53461    public string Dump(DumpParams dumpParams) =>
 49662        DumpR(dumpParams, null, 0);
 53463
 53464    private string DumpR(DumpParams dumpParams, string? prefix, int level) =>
 370365        string.Join(
 370366            Environment.NewLine,
 370367            Enumerable
 370368                .Repeat(
 370369                    (prefix == null ? "" : $"{prefix} {dumpParams.EdgeNodeSeparator} ") +
 370370                    ToString() +
 370371                    (SuffixLink == null ? "" : $" {dumpParams.SuffixLinkSeparator} {SuffixLink}"),
 370372                    1)
 370373                .Concat(
 370374                    from c in Children
 320775                    let indentation = new string(dumpParams.IndentationChar, level + 1)
 320776                    let edgeText = $"'{dumpParams.Text[c.Key.Start..(c.Key.End.Value + 1)]}'"
 320777                    let edgeCompressed = c.Key.ToString(dumpParams.GlobalEnd)
 691078                    select c.Value.DumpR(dumpParams, $"{indentation}{edgeText}{edgeCompressed}", level + 1)));
 53479}