Exemplo n.º 1
0
        /// <summary>
        /// Searches for a name in the ordered list that matches per the <see cref="s_caseInsensitiveComparer" />.
        /// </summary>
        private int BinarySearch(string name)
        {
            var nameSlice = new StringSlice(name);
            int max       = _nodes.Length - 1;
            int min       = 0;

            while (max >= min)
            {
                int mid = min + ((max - min) >> 1);

                var comparison = s_caseInsensitiveComparer.Compare(GetNameSlice(mid), nameSlice);
                if (comparison < 0)
                {
                    min = mid + 1;
                }
                else if (comparison > 0)
                {
                    max = mid - 1;
                }
                else
                {
                    return(mid);
                }
            }

            return(-1);
        }
Exemplo n.º 2
0
        private static int BinarySearch(string concatenatedNames, ImmutableArray <Node> nodes, string name)
        {
            var nameSlice = new StringSlice(name);
            var max       = nodes.Length - 1;
            var min       = 0;

            while (max >= min)
            {
                var mid = min + ((max - min) >> 1);

                var comparison = s_caseInsensitiveComparer.Compare(
                    GetNameSlice(concatenatedNames, nodes, mid), nameSlice);
                if (comparison < 0)
                {
                    min = mid + 1;
                }
                else if (comparison > 0)
                {
                    max = mid - 1;
                }
                else
                {
                    return(mid);
                }
            }

            return(-1);
        }