< Summary

Information
Class: MoreStructures.SuffixTries.SuffixTrieNode
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/SuffixTries/SuffixTrieNode.cs
Line coverage
100%
Covered lines: 49
Uncovered lines: 0
Coverable lines: 49
Total lines: 77
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
.ctor(...)100%8100%
get_Children()100%1100%
get_Start()100%1100%
get_Item(...)100%1100%
ToString()100%1100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/SuffixTries/SuffixTrieNode.cs

#LineLine coverage
 1using MoreStructures.RecImmTrees;
 2using MoreStructures.RecImmTrees.Conversions;
 3using MoreStructures.SuffixStructures;
 4using MoreStructures.Utilities;
 5
 6namespace MoreStructures.SuffixTries;
 7
 8/// <summary>
 9/// An immutable node of an immutable Suffix Trie, recursively pointing to its children nodes via
 10/// <see cref="SuffixTrieEdge"/> instances, associated with selector characters.
 11/// </summary>
 12/// <param name="Children">The collection of children for the node, indexed by single char edges.</param>
 13/// <param name="Start">
 14///     <inheritdoc cref="ISuffixStructureNode{TEdge, TNode}.Start" path="/summary"/>
 15/// </param>
 16/// <remarks>
 17///     <para id="advantages">
 18///     ADVANTAGES AND DISADVANTAGES
 19///     <br/>
 20///     Compare to suffix trees, suffix tries, although less performant and optimized on many operations, are simpler
 21///     to build, navigate and understand.
 22///     </para>
 23///     <para id="immutability">
 24///     IMMUTABILITY
 25///     <br/>
 26///     Immutability is guaranteed by using <see cref="ValueReadOnlyCollection{T}"/>.
 27///     </para>
 28/// </remarks>
 2228929public abstract record SuffixTrieNode(IDictionary<SuffixTrieEdge, SuffixTrieNode> Children, int? Start)
 2228930    : ISuffixStructureNode<SuffixTrieEdge, SuffixTrieNode>
 2228931{
 2228932    /// <summary>
 2228933    /// Builds an intermediate node, i.e. a node with children and their corresponding incoming edges.
 2228934    /// </summary>
 2228935    public record Intermediate(IDictionary<SuffixTrieEdge, SuffixTrieNode> Children)
 1170936        : SuffixTrieNode(Children, null);
 2228937
 2228938    /// <summary>
 2228939    /// Builds a leaf, i.e. a node with no children and the start index of the suffix in the text.
 2228940    /// </summary>
 2063041    public record Leaf(int LeafStart)
 1057542        : SuffixTrieNode(new Dictionary<SuffixTrieEdge, SuffixTrieNode> { }, LeafStart);
 2228943
 2228944    /// <inheritdoc/>
 4618645    public IDictionary<SuffixTrieEdge, SuffixTrieNode> Children { get; }
 2229246        = (Children.Any() == (Start == null)) && Start.GetValueOrDefault(0) >= 0
 2229247        ? Children.ToValueReadOnlyDictionary()
 2229248        : throw new ArgumentException($"Leafs needs to specificy a non-negative {nameof(Start)}.", nameof(Children));
 2228949
 2228950    /// <inheritdoc/>
 2243551    public int? Start { get; } = Start;
 2228952
 2228953    /// <summary>
 2228954    /// Indexes into the children of this node, by edge, which is a single char selector.
 2228955    /// </summary>
 7956    public SuffixTrieNode this[SuffixTrieEdge edge] => Children[edge];
 2228957
 158    private static readonly IStringifier<SuffixTrieEdge, SuffixTrieNode> Stringifier =
 159        new FullyIterativeStringifier<SuffixTrieEdge, SuffixTrieNode>(
 960            r => r.IsLeaf() ? $"R from {r.Start}" : "R",
 2061            (e, n) => $"{e} -> {(n.IsLeaf() ? $"L from {n.Start}" : "I")}")
 162        {
 163            StopIndentingLevel = 10,
 164        };
 2228965
 2228966    /// <inheritdoc path="//*[not(self::summary or self::remarks)]"/>
 2228967    /// <summary>
 2228968    ///     <inheritdoc/>
 2228969    ///     <br/>
 2228970    ///     Uses a <see cref="IStringifier{TEdge, TNode}"/> to generate the string which show the node and its
 2228971    ///     underlying structure.
 2228972    /// </summary>
 2228973    /// <remarks>
 2228974    /// Sealed to prevent compiler from superceding <see cref="ToString()"/> in derived record.
 2228975    /// </remarks>
 976    public sealed override string ToString() => Stringifier.Stringify(this);
 2228977}