예제 #1
0
        /// <summary> Binary search for an object</summary>
        /// <param name="set_Renamed">The collection of <code>Ordered</code> objects.
        /// </param>
        /// <param name="ref_Renamed">The name to search for.
        /// </param>
        /// <param name="lo">The lower index within which to look.
        /// </param>
        /// <param name="hi">The upper index within which to look.
        /// </param>
        /// <returns> The index at which reference was found or is to be inserted.
        /// </returns>
        public static int Bsearch(ISortable set_Renamed, IOrdered ref_Renamed, int lo, int hi)
        {
            int      num;
            int      mid;
            IOrdered ordered;
            int      half;
            int      result;
            int      ret;

            ret = -1;

            num     = (hi - lo) + 1;
            ordered = null;
            while ((-1 == ret) && (lo <= hi))
            {
                half    = num / 2;
                mid     = lo + ((0 != (num & 1))?half:half - 1);
                ordered = set_Renamed.Fetch(mid, ordered);
                result  = ref_Renamed.Compare(ordered);
                if (0 == result)
                {
                    ret = mid;
                }
                else if (0 > result)
                {
                    hi  = mid - 1;
                    num = ((0 != (num & 1))?half:half - 1);
                }
                else
                {
                    lo  = mid + 1;
                    num = half;
                }
            }
            if (-1 == ret)
            {
                ret = lo;
            }

            return(ret);
        }
예제 #2
0
        /// <summary> Binary search for an object</summary>
        /// <param name="array">The array of <code>Ordered</code> objects.
        /// </param>
        /// <param name="ref_Renamed">The name to search for.
        /// </param>
        /// <param name="lo">The lower index within which to look.
        /// </param>
        /// <param name="hi">The upper index within which to look.
        /// </param>
        /// <returns> The index at which reference was found or is to be inserted.
        /// </returns>
        public static int Bsearch(IOrdered[] array, IOrdered ref_Renamed, int lo, int hi)
        {
            int num;
            int mid;
            int half;
            int result;
            int ret;

            ret = -1;

            num = (hi - lo) + 1;
            while ((-1 == ret) && (lo <= hi))
            {
                half   = num / 2;
                mid    = lo + ((0 != (num & 1))?half:half - 1);
                result = ref_Renamed.Compare(array[mid]);
                if (0 == result)
                {
                    ret = mid;
                }
                else if (0 > result)
                {
                    hi  = mid - 1;
                    num = ((0 != (num & 1))?half:half - 1);
                }
                else
                {
                    lo  = mid + 1;
                    num = half;
                }
            }
            if (-1 == ret)
            {
                ret = lo;
            }

            return(ret);
        }
		/// <summary> Binary search for an object</summary>
		/// <param name="array">The array of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <param name="lo">The lower index within which to look.
		/// </param>
		/// <param name="hi">The upper index within which to look.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int Bsearch(IOrdered[] array, IOrdered ref_Renamed, int lo, int hi)
		{
			int num;
			int mid;
			int half;
			int result;
			int ret;
			
			ret = - 1;
			
			num = (hi - lo) + 1;
			while ((- 1 == ret) && (lo <= hi))
			{
				half = num / 2;
				mid = lo + ((0 != (num & 1))?half:half - 1);
				result = ref_Renamed.Compare(array[mid]);
				if (0 == result)
					ret = mid;
				else if (0 > result)
				{
					hi = mid - 1;
					num = ((0 != (num & 1))?half:half - 1);
				}
				else
				{
					lo = mid + 1;
					num = half;
				}
			}
			if (- 1 == ret)
				ret = lo;
			
			return (ret);
		}
		/// <summary> Binary search for an object</summary>
		/// <param name="set_Renamed">The collection of <code>Ordered</code> objects.
		/// </param>
		/// <param name="ref_Renamed">The name to search for.
		/// </param>
		/// <param name="lo">The lower index within which to look.
		/// </param>
		/// <param name="hi">The upper index within which to look.
		/// </param>
		/// <returns> The index at which reference was found or is to be inserted.
		/// </returns>
		public static int Bsearch(ISortable set_Renamed, IOrdered ref_Renamed, int lo, int hi)
		{
			int num;
			int mid;
			IOrdered ordered;
			int half;
			int result;
			int ret;
			
			ret = - 1;
			
			num = (hi - lo) + 1;
			ordered = null;
			while ((- 1 == ret) && (lo <= hi))
			{
				half = num / 2;
				mid = lo + ((0 != (num & 1))?half:half - 1);
				ordered = set_Renamed.Fetch(mid, ordered);
				result = ref_Renamed.Compare(ordered);
				if (0 == result)
					ret = mid;
				else if (0 > result)
				{
					hi = mid - 1;
					num = ((0 != (num & 1))?half:half - 1);
				}
				else
				{
					lo = mid + 1;
					num = half;
				}
			}
			if (- 1 == ret)
				ret = lo;
			
			return (ret);
		}