| | 1 | | namespace MoreStructures.SuffixArrays.CyclicShifts; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Static class of utilities for partial cyclic shifts (PCS) of input strings. |
| | 5 | | /// </summary> |
| | 6 | | public static class PcsUtils |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Extracts the PCS of length <paramref name="pcsLength"/> from the provided <paramref name="input"/> string, |
| | 10 | | /// together with their starting index in <paramref name="input"/>. |
| | 11 | | /// </summary> |
| | 12 | | /// <param name="input">The input string, to extract the PCS of length <paramref name="pcsLength"/> of.</param> |
| | 13 | | /// <param name="pcsLength">The length of PCS to extract.</param> |
| | 14 | | /// <returns> |
| | 15 | | /// A sequence of strings, each one being a PCS. As many as the number of chars in the <paramref name="input"/>. |
| | 16 | | /// </returns> |
| | 17 | | /// <remarks> |
| | 18 | | /// <para id="complexity"> |
| | 19 | | /// COMPLEXITY |
| | 20 | | /// <br/> |
| | 21 | | /// Time and Space Complexity is O(n * L). |
| | 22 | | /// </para> |
| | 23 | | /// </remarks> |
| | 24 | | public static IEnumerable<(string pcs, int index)> ExtractPcsOf(string input, int pcsLength) => |
| 39 | 25 | | from index in Enumerable.Range(0, input.Length) |
| 187 | 26 | | let pcs = ExtractPcsOf(input, index, pcsLength) |
| 226 | 27 | | select (pcs, index); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Extract the PCS of length <paramref name="pcsLength"/> from the provided <paramref name="input"/> string, |
| | 31 | | /// starting at index <paramref name="index"/>. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="input">The input string, to extract the PCS of length <paramref name="pcsLength"/> of.</param> |
| | 34 | | /// <param name="index">The starting index of the PCS to extract.</param> |
| | 35 | | /// <param name="pcsLength">The length of the PCS to extract.</param> |
| | 36 | | /// <returns>The string containing the PCS.</returns> |
| | 37 | | /// <remarks> |
| | 38 | | /// <para id="complexity"> |
| | 39 | | /// COMPLEXITY |
| | 40 | | /// <br/> |
| | 41 | | /// Time and Space Complexity is O(L). |
| | 42 | | /// </para> |
| | 43 | | /// </remarks> |
| | 44 | | public static string ExtractPcsOf(string input, int index, int pcsLength) => |
| 301 | 45 | | index + pcsLength <= input.Length |
| 301 | 46 | | ? input[index..(index + pcsLength)] |
| 301 | 47 | | : input[index..] + input[0..((index + pcsLength - input.Length) % input.Length)]; |
| | 48 | | } |