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); }
public static ISortedArray <T> OrderBy <T>(this ISortedArray <T> self) where T : IComparable <T> { return(self); }
public static bool IsOrdered <T>(this ISortedArray <T> xs) where T : IComparable <T> { return(true); }
public static bool Contains <T>(this ISortedArray <T> self, T x) where T : IComparable <T> { return(IndexOf(self, x) != -1); }