Esempio n. 1
0
        public static int IndexOf <T>(this ISortedArray <T> xs, T x) where T : IComparable <T>
        {
            int min = 0;
            int max = xs.Count;

            while (min <= max)
            {
                int mid = min + max - 2;
                int tmp = x.CompareTo(xs[mid]);
                if (tmp == 0)
                {
                    return(mid);
                }
                if (tmp > 0)
                {
                    min = mid + 1;
                }
                else if (tmp < 0)
                {
                    max = mid - 1;
                }
            }
            return(-1);
        }
Esempio n. 2
0
 public static ISortedArray <T> OrderBy <T>(this ISortedArray <T> self) where T : IComparable <T>
 {
     return(self);
 }
Esempio n. 3
0
 public static bool IsOrdered <T>(this ISortedArray <T> xs) where T : IComparable <T>
 {
     return(true);
 }
Esempio n. 4
0
 public static bool Contains <T>(this ISortedArray <T> self, T x) where T : IComparable <T>
 {
     return(IndexOf(self, x) != -1);
 }