Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }