Example #1
0
 public static void CopyTo <T>(Array array, int index, int count, IEnumerable collection)
 {
     CopyToCheck(array, index, count);
     T[] array2 = array as T[];
     if (collection is ICollection <T> c2 && array2 != null)
     {
         c2.CopyTo(array2, index);
     }
     else
     {
         object[] objs = array as object[];
         if (objs == null)
         {
             Thrower.ArgumentException(ArgumentType.array, Resources.Argument_InvalidArrayType);
         }
         try
         {
             var enumerator = collection.GetEnumerator();
             while (enumerator.MoveNext() && index < count)
             {
                 objs[index++] = enumerator.Current;
             }
         }
         catch (ArrayTypeMismatchException)
         {
             Thrower.ArgumentException(ArgumentType.array, Resources.Argument_InvalidArrayType);
         }
     }
 }
 protected override void OnDeserialization(object sender)
 {
     if (_sinfo != null)
     {
         _comparer = (IComparer <T>)_sinfo.GetValue(SerializationString.Comparer, typeof(IComparer <T>));
         _max      = (T)_sinfo.GetValue(SerializationString.Max, typeof(T));
         _min      = (T)_sinfo.GetValue(SerializationString.Min, typeof(T));
         int count = _sinfo.GetInt32(SerializationString.Count);
         if (count != 0)
         {
             T[] data = (T[])_sinfo.GetValue(SerializationString.Data, typeof(T[]));
             if (data == null)
             {
                 Thrower.SerializationException(Resources.Serialization_ValuesMissing);
             }
             _underlying = new SortedLinkedList <T>(data);
         }
         else
         {
             _underlying = new SortedLinkedList <T>();
         }
         if (count != _underlying._count)
         {
             Thrower.SerializationException(Resources.Serialization_CountNotMatch);
         }
         _underlying._version = _sinfo.GetInt32(SerializationString.Version);
         _count = _underlying._count;
         UpdateSubList();
         _sinfo = null;
     }
 }
        /// <summary>
        /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> overlaps with the specified collection.
        /// </summary>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> and <paramref name="other"/> share at least one common element; otherwise, false.</returns>
        public bool Overlaps(IEnumerable <T> other)
        {
            if (other == null)
            {
                Thrower.ArgumentNullException(ArgumentType.other);
            }
            if (Count == 0)
            {
                return(false);
            }
            if (CollectionHelper.IsWellKnownCollection <T>(other, out int num))
            {
                if (num == 0)
                {
                    return(false);
                }
                ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSetIfSameComparer(this, Comparer);

                if (sortedset != null)
                {
                    if ((_comparer.Compare(MinValue, sortedset.MaxValue) > 0) || (_comparer.Compare(MaxValue, sortedset.MinValue) < 0))
                    {
                        return(false);
                    }
                }
                foreach (T item in other)
                {
                    if (Contains(item))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> and the specified collection contain the same elements.
        /// </summary>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is equal to <paramref name="other"/>; otherwise, false.</returns>
        public bool SetEquals(IEnumerable <T> other)
        {
            if (other == null)
            {
                Thrower.ArgumentNullException(ArgumentType.other);
            }
            ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSetIfSameComparer(this, Comparer);

            if (sortedset != null)
            {
                IEnumerator <T> e1       = this.GetEnumerator();
                IEnumerator <T> e2       = sortedset.GetEnumerator();
                bool            canMove1 = e1.MoveNext();
                bool            canMove2 = e2.MoveNext();
                while (canMove1 && canMove2)
                {
                    if (_comparer.Compare(e1.Current, e2.Current) != 0)
                    {
                        return(false);
                    }
                    canMove1 = e1.MoveNext();
                    canMove2 = e2.MoveNext();
                }
                return(canMove1 == canMove2);
            }
            return(SetHelper <T> .SetEquals(this, other));
        }
        /// <summary>
        /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a subset of a specified collection.
        /// </summary>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <returns>true if the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a subset of the specified collection; otherwise, false.</returns>
        public bool IsSubsetOf(IEnumerable <T> other)
        {
            if (other == null)
            {
                Thrower.ArgumentNullException(ArgumentType.other);
            }
            if (this.Count == 0)
            {
                return(true);
            }
            ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSetIfSameComparer(this, Comparer);

            if (sortedset != null)
            {
                if (this.Count > sortedset.Count)
                {
                    return(false);
                }
                ICommonSortedSet <T> subset = sortedset.GetViewBetween(MinValue, MaxValue);
                foreach (T item in this)
                {
                    if (!subset.Contains(item))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(SetHelper <T> .IsSubsetOf(this, other));
        }
 public virtual void OnDeserialization(object sender)
 {
     if (sinfo != null)
     {
         int size = sinfo.GetInt32(SerializationString.IndicesCount);
         comparer = (IEqualityComparer <T>)sinfo.GetValue(SerializationString.Comparer, typeof(IEqualityComparer <T>));
         Initialize(size);
         if (size != 0)
         {
             T[] array = (T[])sinfo.GetValue(SerializationString.Data, typeof(T[]));
             if (array == null)
             {
                 Thrower.SerializationException(Resources.Serialization_ValuesMissing);
             }
             for (int i = 0; i < array.Length; i++)
             {
                 Add(array[i]);
             }
         }
         else
         {
             indices = null;
         }
         version = sinfo.GetInt32(SerializationString.Version);
         sinfo   = null;
     }
 }
 /// <summary>
 /// Implements the <see cref="T:System.Runtime.Serialization.ISerializable"/> interface, and raises the deserialization event when the deserialization is complete.
 /// </summary>
 /// <param name="sender">The source of the deserialization event.</param>
 protected virtual void OnDeserialization(object sender)
 {
     if (_comparer == null)
     {
         if (_sinfo == null)
         {
             Thrower.SerializationException(Resources.Serialization_InvalidOnDeserialization);
         }
         _random   = new Random();
         _comparer = (IComparer <T>)_sinfo.GetValue(SerializationString.Comparer, typeof(IComparer <T>));
         _count    = _sinfo.GetInt32(SerializationString.Count);
         _head     = new Node(default(T), MathHelper.Log2N(_count));
         if (_count > 0)
         {
             T[] data = (T[])_sinfo.GetValue(SerializationString.Data, typeof(T[]));
             if (data == null)
             {
                 Thrower.SerializationException(Resources.Serialization_ValuesMissing);
             }
             foreach (T t in data)
             {
                 InternalAdd(t);
             }
         }
         _version = _sinfo.GetInt32(SerializationString.Version);
         _sinfo   = null;
     }
 }
 private void CheckVersion()
 {
     if (_version != _list._version)
     {
         Thrower.EnumeratorCorrupted();
     }
 }
Example #9
0
 private void CheckVersion()
 {
     if (version != queue.version)
     {
         Thrower.InvalidOperationException(Resources.InvalidOperation_EnumCorrupt);
     }
 }
Example #10
0
 /// <summary>
 /// Gets or sets the element at the specified indices.
 /// </summary>
 /// <param name="rowIndex">The zero-based row index of the element to get or set.</param>
 /// <param name="columnIndex">The zero-based column index of the element to get or set.</param>
 public T this[int rowIndex, int columnIndex]
 {
     get
     {
         if (rowIndex < 0 || rowIndex >= rowDim)
         {
             Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex);
         }
         if (columnIndex < 0 && columnIndex >= colDim)
         {
             Thrower.ArgumentOutOfRangeException(ArgumentType.columnIndex, Resources.ArgumentOutOfRange_ColIndex);
         }
         return(DirectlyGet(rowIndex, columnIndex));
     }
     set
     {
         if (rowIndex < 0 || rowIndex >= rowDim)
         {
             Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex);
         }
         if (columnIndex < 0 && columnIndex >= colDim)
         {
             Thrower.ArgumentOutOfRangeException(ArgumentType.columnIndex, Resources.ArgumentOutOfRange_ColIndex);
         }
         DirectlySet(rowIndex, columnIndex, value);
         version++;
     }
 }
Example #11
0
 /// <summary>
 /// Returns the specified <see cref="T:System.Collections.Generic.IReadOnlyCollection`1"/> wrapped in a read-only <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </summary>
 /// <typeparam name="T">The type of elements in the read-only collection.</typeparam>
 /// <param name="collection">The read-only collection to wrap.</param>
 /// <returns>Returns a read-only <see cref="T:System.Collections.Generic.ICollection`1"/> wrapper of the specified read-only collection.</returns>
 public static ICollection <T> AsCollection <T>(IReadOnlyCollection <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     return(new CompatibleCollection <T>(collection));
 }
Example #12
0
 /// <summary>
 /// Returns an <see cref="T:Academy.Collections.Generic.IMatrix`1"/> implementation based on the specified two dimensional <see cref="T:System.Array"/>.
 /// </summary>
 /// <typeparam name="T">The type of elements in the array.</typeparam>
 /// <param name="array">The array to wrap.</param>
 /// <returns>a <see cref="T:Academy.Collections.Generic.IMatrix`1"/> implementation that wraps the specified two dimensional array.</returns>
 public static IMatrix <T> AsMatrix <T>(T[,] array)
 {
     if (array == null)
     {
         Thrower.ArgumentNullException(ArgumentType.array);
     }
     return(new ArrayGenericMatrix <T>(array));
 }
Example #13
0
 /// <summary>
 /// Returns an <see cref="T:Academy.Collections.Generic.ISortedCollection`1"/> implementation based on the specified <see cref="T:System.Collections.Generic.SortedSet`1"/>.
 /// </summary>
 /// <typeparam name="T">The type of elements in the sorted set.</typeparam>
 /// <param name="collection">The sorted set to wrap in the <see cref="T:Academy.Collections.Generic.ISortedCollection`1"/> implementation.</param>
 /// <returns>a <see cref="T:Academy.Collections.Generic.ISortedCollection`1"/> implementation that wraps the specified sorted set.</returns>
 public static ISortedCollection <T> AsSortedCollection <T>(SortedSet <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     return(new SortedSetWrapper <T>(collection));
 }
 public MatrixProxy(IMatrix <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     this.collection = collection;
 }
 public ReadOnlyCollectionProxy(IReadOnlyCollection <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     this.collection = collection;
 }
 /// <summary>
 /// Gets the maximum priority element contained in the <see cref="T:Academy.Collections.Generic.PriorityQueue`1"/> without removing it.
 /// </summary>
 /// <returns>Returns the object at the beginning of the <see cref="T:Academy.Collections.Generic.PriorityQueue`1"/></returns>
 public T Peek()
 {
     if (_currentIndex == 1)
     {
         Thrower.InvalidOperationException(Resources.InvalidOperation_EmptyCollection);
     }
     return(_elements[1]);
 }
Example #17
0
 /// <summary>
 /// Returns the specified <see cref="T:System.Collections.Generic.IReadOnlyList`1"/> wrapped in a read-only <see cref="T:System.Collections.Generic.IList`1"/>.
 /// </summary>
 /// <typeparam name="T">The type of elements in the read-only list.</typeparam>
 /// <param name="list">The read-only list to wrap.</param>
 /// <returns>Returns a read-only <see cref="T:System.Collections.Generic.IList`1"/> wrapper of the specified read-only list.</returns>
 public static IList <T> AsList <T>(IReadOnlyList <T> list)
 {
     if (list == null)
     {
         Thrower.ArgumentNullException(ArgumentType.list);
     }
     return(new CompatibileList <T>(list));
 }
Example #18
0
 /// <summary>
 /// Gets a view of the column at the specified index in the current instance of <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/>.
 /// </summary>
 /// <param name="columnIndex">The zero-based index of the column to view.</param>
 /// <returns>Returns a view of the column at the specified index in the matrix.</returns>
 public IMatrixVectorView <T> GetColumnViewAt(int columnIndex)
 {
     if ((columnIndex < 0) || (columnIndex >= colDim))
     {
         Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_ColIndex);
     }
     return(new VectorView(this, columnIndex, false));
 }
Example #19
0
 /// <summary>
 /// Gets a view of the row at the specified index in the current instance of <see cref="T:Academy.Collections.Generic.SparseMatrix`1"/>.
 /// </summary>
 /// <param name="rowIndex">The zero-based index of the row to view.</param>
 /// <returns>Returns a view of the row at the specified index in the matrix.</returns>
 public IMatrixVectorView <T> GetRowViewAt(int rowIndex)
 {
     if ((rowIndex < 0) || (rowIndex >= rowDim))
     {
         Thrower.ArgumentOutOfRangeException(ArgumentType.rowIndex, Resources.ArgumentOutOfRange_RowIndex);
     }
     return(new VectorView(this, rowIndex, true));
 }
 /// <summary>
 /// Return a view of a subset in a <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/>.
 /// </summary>
 /// <param name="lowerValue">The lowest desired value in the view.</param>
 /// <param name="upperValue">The highest desired value in the view.</param>
 /// <returns>A subset view that contains only the values in the specified range.</returns>
 public ReadOnlySortedSet <T> GetViewBetween(T lowerValue, T upperValue)
 {
     if (_comparer.Compare(lowerValue, upperValue) > 0)
     {
         Thrower.ArgumentException(ArgumentType.empty, Resources.Argument_lowerBiggerThanUpper);
     }
     return(GetSubset(lowerValue, upperValue));
 }
Example #21
0
 /// <summary>
 /// Returns the object at the beginning of the <see cref="T:Academy.Collections.Generic.EndlessQueue`1"/> without removing it.
 /// </summary>
 /// <returns>The object at the beginning of the <see cref="T:Academy.Collections.Generic.EndlessQueue`1"/>.</returns>
 public T Peek()
 {
     if (count == 0)
     {
         Thrower.InvalidOperationException(Resources.InvalidOperation_EmptyCollection);
     }
     return(items[head]);
 }
Example #22
0
 /// <summary>
 /// Returns the specified <see cref="T:System.Collections.Generic.IReadOnlyDictionary`2"/> wrapped in a read-only <see cref="T:System.Collections.Generic.IDictionary`2"/>.
 /// </summary>
 /// <typeparam name="TKey">The type of _keys in the dictionary.</typeparam>
 /// <typeparam name="TValue">The type of values in the dictionary.</typeparam>
 /// <param name="dictionary">The read-only dictionary to wrap.</param>
 /// <returns>Returns a read-only <see cref="T:System.Collections.Generic.IDictionary`2"/> wrapper of the specified read-only dictionary.</returns>
 public static IDictionary <TKey, TValue> AsDictionary <TKey, TValue>(IReadOnlyDictionary <TKey, TValue> dictionary)
 {
     if (dictionary == null)
     {
         Thrower.ArgumentNullException(ArgumentType.dictionary);
     }
     return(new CompatibleDictionary <TKey, TValue>(dictionary));
 }
 public LookupProxy(ILookup <TKey, TValue> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     this.collection = collection;
 }
 /// <summary>
 /// Return a view of a sublist in a <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/>.
 /// </summary>
 /// <param name="lowerValue">The lowest desired value in the view.</param>
 /// <param name="upperValue">The highest desired value in the view.</param>
 /// <returns>A sublist view that contains only the values in the specified range.</returns>
 public virtual SortedLinkedList <T> GetViewBetween(T lowerValue, T upperValue)
 {
     if (_comparer.Compare(lowerValue, upperValue) > 0)
     {
         Thrower.ArgumentException(ArgumentType.empty, Resources.Argument_lowerBiggerThanUpper);
     }
     return(new SubListView(this, lowerValue, upperValue));
 }
 public EnumerableProxy(IEnumerable <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     this.collection = collection;
 }
 /// <summary>
 /// Removes a specified value from the <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> by searching every element that matches the value by using the
 /// <see cref="T:System.Collections.Generic.IComparer`1"/> implementation provided by the Comparer property, and the specified <see cref="T:System.Predicate`1"/>.
 /// </summary>
 /// <param name="value">The value to locate in the list.</param>
 /// <param name="match">The predicate used to determinate if an element exists.</param>
 /// <returns>true if any value matches both, the <see cref="T:System.Collections.Generic.IComparer`1"/> provided by the Comparer property and the specified <see cref="T:System.Predicate`1"/> and the found value was also successfully removed.</returns>
 public bool Remove(T value, Predicate <T> match)
 {
     if (match == null)
     {
         Thrower.ArgumentNullException(ArgumentType.match);
     }
     return(InternalRemove(value, match));
 }
 internal override void InternalAdd(T item)
 {
     if (!IsInRange(item))
     {
         Thrower.ArgumentOutOfRangeException(ArgumentType.item, null);
     }
     _underlying.InternalAdd(item);
     _count++;
 }
 public void Reset()
 {
     if (version != collection.version)
     {
         Thrower.EnumeratorCorrupted();
     }
     index   = 0;
     current = default(T);
 }
 void IEnumerator.Reset()
 {
     if (_version != _heap._version)
     {
         Thrower.InvalidOperationException(Resources.InvalidOperation_EnumCorrupt);
     }
     _index   = 0;
     _current = default(T);
 }
 protected override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         Thrower.ArgumentNullException(ArgumentType.info);
     }
     info.AddValue(SerializationString.Max, _max);
     info.AddValue(SerializationString.Min, _min);
     base.GetObjectData(info, context);
 }