| | 1 | | namespace MoreStructures.SuffixTrees.Builders.Ukkonen; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// An edge of the tree structure built by <see cref="UkkonenSuffixTreeBuilder"/>, expressed with label compression. |
| | 5 | | /// </summary> |
| | 6 | | /// <remarks> |
| | 7 | | /// Mutable and using a <see cref="MovingEnd"/> to have leaves updated by Rule 1 Extension in constant time. |
| | 8 | | /// </remarks> |
| | 9 | | internal class MutableEdge |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// The index (in the text) of the first char of the label associated with this edge. |
| | 13 | | /// </summary> |
| 12308 | 14 | | public int Start { get; } |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// The index (in the text) of the last char of the label associated with this edge. |
| | 18 | | /// </summary> |
| 12239 | 19 | | public MovingEnd End { get; set; } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// <inheritdoc cref="MutableEdge"/> |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="start"><inheritdoc cref="Start" path="/summary"/></param> |
| | 25 | | /// <param name="end"><inheritdoc cref="End" path="/summary"/></param> |
| 607 | 26 | | public MutableEdge(int start, MovingEnd end) |
| 607 | 27 | | { |
| 607 | 28 | | Start = start; |
| 607 | 29 | | End = end; |
| 607 | 30 | | } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// The length of this edge. |
| | 34 | | /// </summary> |
| | 35 | | /// <value> |
| | 36 | | /// A positive value (at least 1). |
| | 37 | | /// </value> |
| 14 | 38 | | public int Length => End.Value - Start + 1; |
| | 39 | |
|
| | 40 | | /// <inheritdoc path="//*[not(self::summary)]"/> |
| | 41 | | /// <summary> |
| | 42 | | /// <inheritdoc/>. |
| | 43 | | /// <br/> |
| | 44 | | /// To assess equality, <see cref="Start"/> and <see cref="MovingEnd.Value"/> of <see cref="End"/> are |
| | 45 | | /// compared. |
| | 46 | | /// </summary> |
| | 47 | | public override bool Equals(object? obj) => |
| 554 | 48 | | obj is MutableEdge edge && Equals(Start, edge.Start) && Equals(End.Value, edge.End.Value); |
| | 49 | |
|
| | 50 | | /// <inheritdoc path="//*[not(self::summary)]"/> |
| | 51 | | /// <summary> |
| | 52 | | /// <inheritdoc/>. |
| | 53 | | /// <br/> |
| | 54 | | /// Calculated based on <see cref="Start"/> only, since <see cref="End"/> is subject to mutation. |
| | 55 | | /// </summary> |
| | 56 | | public override int GetHashCode() => |
| 910 | 57 | | Start; |
| | 58 | |
|
| | 59 | | /// <inheritdoc path="//*[not(self::summary)]"/> |
| | 60 | | /// <summary> |
| | 61 | | /// In the form [<see cref="Start"/>, <see cref="End"/>] or [<see cref="Start"/>, <see cref="End"/>*], if the |
| | 62 | | /// <see cref="End"/> of this <see cref="MutableEdge"/> is the provided <paramref name="globalEnd"/>. |
| | 63 | | /// </summary> |
| | 64 | | /// <param name="globalEnd">The <see cref="MovingEnd"/> to stringify.</param> |
| | 65 | | /// <returns> |
| | 66 | | /// A stringified version of this edge, showing presence or absence of <paramref name="globalEnd"/>. |
| | 67 | | /// </returns> |
| | 68 | | public string ToString(MovingEnd globalEnd) => |
| 3207 | 69 | | $"[{Start},{End}{(ReferenceEquals(End, globalEnd) ? "*" : string.Empty)}]"; |
| | 70 | | } |