Example #1
0
        public static int BinarySearchWithTimeRange(this IList <IIndexedDict> items, int[] keysNdxs, object[] keysValues, ITimedObject timeRange)
        {
            int n = items.Count;
            int ia = 0, ib = n - 1;

            while (ia <= ib)
            {
                int i = (ia + ib) / 2;
                int r = Cmp.CompareKeysWithTimeRange(items[i].ValuesList, keysNdxs, keysValues, timeRange);
                if (r > 0)
                {
                    ib = i - 1;
                    if (ib < ia)
                    {
                        return(~i);
                    }
                }
                else if (r < 0)
                {
                    ia = i + 1;
                    if (ib < ia)
                    {
                        return(~ia);
                    }
                }
                else
                {
                    return(i);
                }
            }
            return(~0);
        }
Example #2
0
        public static IEnumerable <int> BinarySearchAllWithTimeRange(this IList <IIndexedDict> items, int[] keysNdxs, object[] keysValues, ITimedObject timeRange)
        {
            if (items == null)
            {
                yield break;
            }
            int n = items.Count;

            if (n == 0)
            {
                yield break;
            }
            int i = BinarySearchWithTimeRange(items, keysNdxs, keysValues, timeRange);

            if (i < 0)
            {
                i = 0; yield break;
            }
            var Imax = i;

            while (i > 0 && Cmp.CompareKeysWithTimeRange(items[i - 1].ValuesList, keysNdxs, keysValues, timeRange) == 0)
            {
                i--;
            }
            var prevEndTime = DateTime.MinValue;

            while (i <= Imax)
            {
#if CHECK_DATA_DUPS
                if (i < Imax && Cmp.CompareTimed(items[i].ValuesList, items[i + 1].ValuesList) == 0)
                {
                    DupDataError(items[i]);
                    i++; continue;
                }
#endif
                yield return(i++);
            }
            while (i < n)
            {
                if (Cmp.CompareKeysWithTimeRange(items[i].ValuesList, keysNdxs, keysValues, timeRange) == 0)
                {
#if CHECK_DATA_DUPS
                    if (Cmp.CompareTimed(items[i - 1].ValuesList, items[i].ValuesList) == 0)
                    {
                        DupDataError(items[i]);
                        i++; continue;
                    }
#endif
                    yield return(i++);
                }
                else
                {
                    yield break;
                }
            }
        }