public static int GetCountByPrefix(IReadOnlyList <string> phrases, string prefix) { int left = My_LeftBorderTask.GetLeftBorderIndex(phrases, prefix, -1, phrases.Count); int right = My_RightBorderTask.GetRightBorderIndex(phrases, prefix, -1, phrases.Count); return(right - left - 1); }
public static string[] GetTopByPrefix(IReadOnlyList <string> phrases, string prefix, int count) { int actualCount = Math.Min(GetCountByPrefix(phrases, prefix), count); int startIndex = My_LeftBorderTask.GetLeftBorderIndex(phrases, prefix, -1, phrases.Count) + 1; string[] result = new string[actualCount]; Array.Copy(phrases.ToArray(), startIndex, result, 0, actualCount); return(result); }
public static string FindFirstByPrefix(IReadOnlyList <string> phrases, string prefix) { var index = My_LeftBorderTask.GetLeftBorderIndex(phrases, prefix, -1, phrases.Count) + 1; if (index < phrases.Count && phrases[index].StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { return(phrases[index]); } else { return(null); } }