Beispiel #1
0
 public static TImpl Create(IReadOnlySeries <TKey, TValue> innerSeries)
 {
     if (Pool == null || !Pool.TryTake(out TImpl instance))
     {
         instance           = new TImpl();
         instance._comparer = KeyComparer <TKey2> .Create(new ConvertComparer(instance));
     }
     instance.Inner = innerSeries;
     return(instance);
 }
Beispiel #2
0
 protected AppendSeries(Mutability mutability       = Mutability.ReadOnly,
                        KeySorting keySorting       = KeySorting.Strong,
                        KeyComparer <TKey> comparer = default,
                        MovingWindowOptions <TKey>?movingWindowOptions = default) : base(mutability, keySorting, comparer)
 {
     if (movingWindowOptions != null)
     {
         WindowOptions = new MovingWindowOptions(this, movingWindowOptions);
     }
 }
Beispiel #3
0
        // There is no ctors for series because they are read-only,
        // only factories in static Series class

        internal Series(Mutability mutability       = Mutability.ReadOnly,
                        KeySorting keySorting       = KeySorting.Strong,
                        KeyComparer <TKey> comparer = default)
        {
            if (keySorting != KeySorting.Strong)
            {
                throw new NotImplementedException();
            }
            Flags     = new Flags(ContainerLayout.Series, keySorting, mutability);
            _comparer = comparer;
        }
Beispiel #4
0
 public bool Equals(KeyComparer <T> other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(_comparer, other._comparer) && Equals(_keyComparer, other._keyComparer));
 }
Beispiel #5
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;
        }
Beispiel #6
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);
        }
Beispiel #7
0
        // There is no ctors for series because they are read-only,
        // only factories in static Series class

        internal Series(Mutability mutability       = Mutability.ReadOnly,
                        KeySorting keySorting       = KeySorting.Strong,
                        KeyComparer <TKey> comparer = default)
        {
            // Need to touch these fields very early in a common not hot place for JIT static
            // readonly optimization even if tiered compilation is off.
            // Note single & to avoid short circuit.
            if (AdditionalCorrectnessChecks.Enabled
                & TypeHelper <TKey> .IsReferenceOrContainsReferences
                & TypeHelper <TValue> .IsReferenceOrContainsReferences)
            {
                ThrowHelper.Assert(!PrivateMemory <TKey> .ObjectPool.IsDisposed);
                ThrowHelper.Assert(!PrivateMemory <TValue> .ObjectPool.IsDisposed);
            }

            if (keySorting != KeySorting.Strong)
            {
                throw new NotImplementedException();
            }
            Flags     = new Flags(ContainerLayout.Series, keySorting, mutability);
            _comparer = comparer;
        }
Beispiel #8
0
 /// <summary>
 /// Create a KVP comparer that only compares keys.
 /// </summary>
 public KVPComparer(KeyComparer <TKey> keyComparer)
 {
     _keyComparer = keyComparer ?? KeyComparer <TKey> .Default;
 }
Beispiel #9
0
 /// <summary>
 /// Create a KVP comparer that only compares keys. Pass null as a second constructor argument
 /// to use a default comparer for values. With this constructor values are ignored.
 /// </summary>
 public KVPComparer(KeyComparer <TKey> keyComparer)
 {
     _keyComparer = keyComparer.Equals(default(KeyComparer <TKey>)) ? KeyComparer <TKey> .Default : keyComparer;
 }
Beispiel #10
0
 /// <summary>
 /// Create a KVP comparer that compares keys and values.
 /// </summary>
 public KVPComparer(KeyComparer <TKey> keyComparer, KeyComparer <TValue> valueComparer)
 {
     _keyComparer   = keyComparer.Equals(default(KeyComparer <TKey>)) ? KeyComparer <TKey> .Default : keyComparer;
     _valueComparer = valueComparer.Equals(default(KeyComparer <TValue>)) ? KeyComparer <TValue> .Default : valueComparer;
 }
Beispiel #11
0
 public AppendSeries(KeyComparer <TKey> comparer, KeySorting keySorting, MovingWindowOptions <TKey> movingWindowOptions)
     : this(Mutability.AppendOnly, keySorting, comparer, movingWindowOptions)
 {
 }
Beispiel #12
0
        protected ConvertSeries(IReadOnlySeries <TKey, TValue> inner)
        {
            Inner = inner;

            _comparer = KeyComparer <TKey2> .Create(new ConvertComparer(this as TImpl));
        }
Beispiel #13
0
 public MutableSeries(KeyComparer <TKey> comparer)
     : base(Mutability.Mutable, KeySorting.Strong, comparer)
 {
 }
Beispiel #14
0
 public VariantComparer(IReadOnlySeries <TKey, TValue> inner)
 {
     _sourceComparer = inner.Comparer;
 }
Beispiel #15
0
 public AppendSeries(KeyComparer <TKey> comparer, KeySorting keySorting)
     : this(Mutability.AppendOnly, keySorting, comparer, default)
 {
 }
Beispiel #16
0
 /// <summary>
 /// Create a KVP comparer that compares keys and values.
 /// </summary>
 public KVPComparer(KeyComparer <TKey> keyComparer, KeyComparer <TValue> valueComparer)
 {
     _keyComparer   = keyComparer ?? KeyComparer <TKey> .Default;
     _valueComparer = valueComparer ?? KeyComparer <TValue> .Default;
 }
Beispiel #17
0
 public MutableSeries(KeyComparer <TKey> comparer, KeySorting keySorting)
     : base(Mutability.Mutable, keySorting, comparer, default)
 {
 }
Beispiel #18
0
 public MutableSeries(KeyComparer <TKey> comparer, KeySorting keySorting, MovingWindowOptions <TKey> movingWindowOptions)
     : base(Mutability.Mutable, keySorting, comparer, movingWindowOptions)
 {
 }
Beispiel #19
0
 public VariantSeries(IReadOnlySeries <TKey, TValue> inner)
 {
     Inner     = inner;
     _comparer = KeyComparer <Variant> .Create(new VariantComparer(Inner));
 }
Beispiel #20
0
 public AppendSeries(KeyComparer <TKey> comparer)
     : this(Mutability.AppendOnly, KeySorting.Strong, comparer)
 {
 }