public static Series <TKey, TValue, Range <TKey, TValue, TCursor> > Range <TKey, TValue, TCursor>(
     this ContainerSeries <TKey, TValue, TCursor> series,
     TKey startKey, TKey endKey, bool startInclusive = true, bool endInclusive = true)
     where TCursor : ISpecializedCursor <TKey, TValue, TCursor>
 {
     // NB cast to Opt for overload resolution
     return(series.Range(Opt.Present(startKey), Opt.Present(endKey), startInclusive, endInclusive));
 }
示例#2
0
        internal static Series <TKey, TValue, Range <TKey, TValue, Cursor <TKey, TValue> > > Range <TKey, TValue>(
            this ISeries <TKey, TValue> series,
            Opt <TKey> startKey, Opt <TKey> endKey, bool startInclusive = true, bool endInclusive = true)
        {
            var cursor = new Range <TKey, TValue, Cursor <TKey, TValue> >(new Cursor <TKey, TValue>(
                                                                              series.GetCursor()), startKey, endKey, startInclusive, endInclusive);

            return(cursor.Source);
        }
示例#3
0
        internal static Series <TKey, TValue, Range <TKey, TValue, SortedChunkedMapCursor <TKey, TValue> > > Range <TKey, TValue>(
            this SortedChunkedMap <TKey, TValue> series,
            Opt <TKey> startKey, Opt <TKey> endKey, bool startInclusive = true, bool endInclusive = true)
        {
            var cursor = new Range <TKey, TValue, SortedChunkedMapCursor <TKey, TValue> >(
                series.GetEnumerator(), startKey, endKey, startInclusive, endInclusive);

            return(cursor.Source);
        }
示例#4
0
        internal static Series <TKey, TValue, Range <TKey, TValue, TCursor> > Range <TKey, TValue, TCursor>(
            this Series <TKey, TValue, TCursor> series,
            Opt <TKey> startKey, Opt <TKey> endKey, bool startInclusive = true, bool endInclusive = true)
            where TCursor : ICursorSeries <TKey, TValue, TCursor>
        {
            var cursor = new Range <TKey, TValue, TCursor>(
                series.GetEnumerator(), startKey, endKey, startInclusive, endInclusive);

            return(cursor.Source);
        }
示例#5
0
        internal static Series <TKey, TValue, Range <TKey, TValue, TCursor> > Range <TKey, TValue, TCursor>(
            this ContainerSeries <TKey, TValue, TCursor> series,
            Opt <TKey> startKey, Opt <TKey> endKey, bool startInclusive = true, bool endInclusive = true)
            where TCursor : ISpecializedCursor <TKey, TValue, TCursor>
        {
            var cursor = new Range <TKey, TValue, TCursor>(
                series.GetContainerCursor(), startKey, endKey, startInclusive, endInclusive);

            return(cursor.Source);
        }
        // TODO make public

        internal static Series <TKey, TResult, Map <TKey, TInput, TResult, Range <TKey, TInput, TCursor> > > After <TKey, TInput, TResult, TCursor>(
            this Series <TKey, TResult, Map <TKey, TInput, TResult, TCursor> > series,
            TKey startKey, bool startInclusive = true)
            where TCursor : ISpecializedCursor <TKey, TInput, TCursor>
        {
            // NB trick - we move range before map, see how all maps are fused below
            // TODO (low) combine ranges in the example below
            var mapInner = series._cursor._cursor;
            var selector = series._cursor._selector;
            var range    = new Range <TKey, TInput, TCursor>(mapInner, Opt.Present(startKey), Opt <TKey> .Missing, startInclusive, true);
            var map      = new Map <TKey, TInput, TResult, Range <TKey, TInput, TCursor> >(range, selector);
            var res      = map.Source;

            return(res);
        }
示例#7
0
        internal Range(TCursor cursor,
                       Opt <TKey> startKey, Opt <TKey> endKey,
                       bool startInclusive = true, bool endInclusive = true,
                       bool isWindow       = false,
                       int count           = -1) : this()
        {
            if (!isWindow && cursor.IsIndexed)
            {
                ThrowHelper.ThrowNotSupportedException("RangeSeries is not supported for indexed series, only for sorted ones.");
            }

            _cmp = cursor.Comparer;

            if (isWindow &&
                (startKey.IsMissing || endKey.IsMissing || !startInclusive || !endInclusive ||
                 _cmp.Compare(cursor.CurrentKey, startKey.Present) != 0))
            {
                ThrowHelper.ThrowInvalidOperationException("Wrong constructor arguments for cursorIsClonedAtStart == true case");
            }

            _cursor = cursor;

            _isWindow = isWindow;

            if (startKey.IsPresent)
            {
                _flags   |= Flags.StartKeyIsPresent;
                _startKey = startKey.Present;
            }

            if (endKey.IsPresent)
            {
                _flags |= Flags.EndKeyIsPresent;
                _endKey = endKey.Present;
            }

            if (startInclusive)
            {
                _flags |= Flags.StartInclusive;
            }

            if (endInclusive)
            {
                _flags |= Flags.EndInclusive;
            }

            _count = count;
        }
示例#8
0
        internal static RangeSeries <TKey, TValue, TCursor> Range <TKey, TValue, TCursor>(
            this RangeSeries <TKey, TValue, TCursor> series,
            Opt <TKey> startKey, Opt <TKey> endKey, bool startInclusive = true, bool endInclusive = true)
            where TCursor : ICursor <TKey, TValue>
        {
            // adjust range to efficiently nest range series, e.g. After(x).Before(y)

            var newStartKey = Opt <TKey> .LargerOrMissing(series.StartKey, startKey, series.Comparer);

            var newStartInclusive = newStartKey.Equals(startKey) ? startInclusive : series.StartInclusive;

            var newEndKey = Opt <TKey> .SmallerOrMissing(series.EndKey, endKey, series.Comparer);

            var newEndInclusive = newEndKey.Equals(endKey) ? endInclusive : series.EndInclusive;

            return(new RangeSeries <TKey, TValue, TCursor>(series,
                                                           newStartKey, newEndKey, newStartInclusive, newEndInclusive));
        }
示例#9
0
        /// <summary>
        /// Return a smaller Opt value or Missing if both are missing. Missing value is treated as larger than a present value.
        /// </summary>
        public static Opt <T> SmallerOrMissing(Opt <T> first, Opt <T> second, KeyComparer <T> comparer)
        {
            if (first.IsMissing && second.IsMissing)
            {
                return(Missing);
            }

            if (first.IsMissing)
            {
                return(second);
            }
            if (second.IsMissing)
            {
                return(first);
            }

            var c = comparer.Compare(first.Value, second.Value);

            return(c <= 0 ? first : second);
        }
示例#10
0
        internal static Series <TKey, TValue, Range <TKey, TValue, TCursor> > Range <TKey, TValue, TCursor>(
            this Series <TKey, TValue, Range <TKey, TValue, TCursor> > series,
            Opt <TKey> startKey, Opt <TKey> endKey, bool startInclusive = true, bool endInclusive = true)
            where TCursor : ISpecializedCursor <TKey, TValue, TCursor>
        {
            // adjust range to efficiently nest range series, e.g. After(x).Before(y)

            var newStartKey = Opt <TKey> .LargerOrMissing(series._cursor.StartKey, startKey, series.Comparer);

            var newStartInclusive = newStartKey.Equals(startKey) ? startInclusive : series._cursor.StartInclusive;

            var newEndKey = Opt <TKey> .SmallerOrMissing(series._cursor.EndKey, endKey, series.Comparer);

            var newEndInclusive = newEndKey.Equals(endKey) ? endInclusive : series._cursor.EndInclusive;

            var cursor = new Range <TKey, TValue, TCursor>(
                series._cursor._cursor, newStartKey, newEndKey, newStartInclusive, newEndInclusive);

            return(cursor.Source);
        }
示例#11
0
 /// <inheritdoc />
 public bool Equals(Opt <T> other)
 {
     return(IsPresent == other.IsPresent && (IsMissing || Value.Equals(other.Value)));
 }
示例#12
0
 public OutOfOrderKeyException(TKey currentKey, string message = "Out of order data") : base(message)
 {
     CurrentKey = Opt.Present(currentKey);
 }
示例#13
0
 public static Series <TKey, TValue, Range <TKey, TValue, Cursor <TKey, TValue> > > Before <TKey, TValue>(
     this ISeries <TKey, TValue> series,
     TKey endKey, bool endInclusive = true)
 {
     return(series.Range(Opt <TKey> .Missing, Opt.Present(endKey), true, endInclusive));
 }
示例#14
0
 public static Series <TKey, TValue, Range <TKey, TValue, Cursor <TKey, TValue> > > After <TKey, TValue>(
     this ISeries <TKey, TValue> series,
     TKey startKey, bool startInclusive = true)
 {
     return(series.Range(Opt.Present(startKey), Opt <TKey> .Missing, startInclusive, true));
 }
示例#15
0
 public static Series <TKey, TValue, Range <TKey, TValue, Cursor <TKey, TValue> > > Range <TKey, TValue>(
     this ISeries <TKey, TValue> series,
     TKey startKey, TKey endKey, bool startInclusive = true, bool endInclusive = true)
 {
     return(series.Range(Opt.Present(startKey), Opt.Present(endKey), startInclusive, endInclusive));
 }