| | 1 | | namespace MoreStructures.SuffixStructures; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extension methods for all <see cref="ISuffixStructureEdge{TEdge, TNode}"/> edge concretions. |
| | 5 | | /// </summary> |
| | 6 | | public static class SuffixStructureEdgeExtensions |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Whether <paramref name="first"/> is in adjacency order w.r.t. <paramref name="second"/>, acoording to the |
| | 10 | | /// provided <paramref name="order"/>. |
| | 11 | | /// </summary> |
| | 12 | | /// <param name="first">The edge to be compared for adjacency.</param> |
| | 13 | | /// <param name="second">The edge to compare the first edge against.</param> |
| | 14 | | /// <param name="order">The adjacency relationship order to use for comparison.</param> |
| | 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 | | /// <returns>True if the specified adjacency relationship is respected.</returns> |
| | 22 | | public static bool IsAdjacentTo<TEdge, TNode>( |
| | 23 | | this ISuffixStructureEdge<TEdge, TNode> first, |
| | 24 | | TEdge second, |
| | 25 | | AdjacencyOrders order = AdjacencyOrders.BeforeOrAfter) |
| | 26 | | where TEdge : ISuffixStructureEdge<TEdge, TNode> |
| | 27 | | where TNode : ISuffixStructureNode<TEdge, TNode> => |
| | 28 | |
|
| 6 | 29 | | (order.HasFlag(AdjacencyOrders.Before) && first.Start + first.Length == second.Start) || |
| 6 | 30 | | (order.HasFlag(AdjacencyOrders.After) && second.Start + second.Length == first.Start); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Whether the provided <paramref name="edge"/> contains the provided <paramref name="index"/>. |
| | 34 | | /// </summary> |
| | 35 | | /// <typeparam name="TEdge"> |
| | 36 | | /// <inheritdoc cref="ISuffixStructureEdge{TEdge, TNode}" path="/typeparam[@name='TEdge']"/> |
| | 37 | | /// </typeparam> |
| | 38 | | /// <typeparam name="TNode"> |
| | 39 | | /// <inheritdoc cref="ISuffixStructureNode{TEdge, TNode}" path="/typeparam[@name='TNode']"/> |
| | 40 | | /// </typeparam> |
| | 41 | | /// <param name="edge">The edge to check.</param> |
| | 42 | | /// <param name="index">The index of the char of the text, to look for. Must be non-negative.</param> |
| | 43 | | /// <returns>A boolean.</returns> |
| | 44 | | public static bool ContainsIndex<TEdge, TNode>( |
| | 45 | | this ISuffixStructureEdge<TEdge, TNode> edge, |
| | 46 | | int index) |
| | 47 | | where TEdge : ISuffixStructureEdge<TEdge, TNode> |
| | 48 | | where TNode : ISuffixStructureNode<TEdge, TNode> => |
| | 49 | |
|
| 1521 | 50 | | index >= 0 |
| 1521 | 51 | | ? edge.Start <= index && index < edge.Start + edge.Length |
| 1521 | 52 | | : throw new ArgumentOutOfRangeException(nameof(index), "Must be non-negative."); |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Whether the provided <paramref name="edge"/> has a <see cref="ISuffixStructureNode{TEdge, TNode}.Start"/> |
| | 56 | | /// lower or equal than the provided <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="edge">The edge to check.</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 ContainsIndexesNonBiggerThan<TEdge, TNode>( |
| | 68 | | this ISuffixStructureEdge<TEdge, TNode> edge, |
| | 69 | | int index) |
| | 70 | | where TEdge : ISuffixStructureEdge<TEdge, TNode> |
| | 71 | | where TNode : ISuffixStructureNode<TEdge, TNode> => |
| | 72 | |
|
| 26 | 73 | | index >= 0 |
| 26 | 74 | | ? edge.Start <= index |
| 26 | 75 | | : throw new ArgumentOutOfRangeException(nameof(index), "Must be non-negative."); |
| | 76 | | } |