/// <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 ReadOnlyCollectionProxy(IReadOnlyCollection <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     this.collection = collection;
 }
Example #5
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));
 }
Example #6
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 #7
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 #8
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));
 }
 public MatrixProxy(IMatrix <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));
 }
 public EnumerableProxy(IEnumerable <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     this.collection = collection;
 }
Example #12
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;
 }
Example #14
0
 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         Thrower.ArgumentNullException(ArgumentType.info);
     }
     info.AddValue(SerializationString.Collection, _heap);
     info.AddValue(SerializationString.Index, _index);
     info.AddValue(SerializationString.Version, _version);
 }
 public void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         Thrower.ArgumentNullException(ArgumentType.info);
     }
     info.AddValue(SerializationString.Collection, _underlying, typeof(ReadOnlySortedSet <T>));
     info.AddValue(SerializationString.LowerIndex, _lowerIndex);
     info.AddValue(SerializationString.UpperIndex, _upperIndex);
 }
 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);
 }
 /// <summary>
 /// Initialize a new instance of the <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> class that contains
 /// elements copied from the especified collection and that uses a specified comparer.
 /// </summary>
 /// <param name="collection">The collection whose elements are copied to the new <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/>.</param>
 /// <param name="comparer">The default comparer to use for compare objects.</param>
 public SortedLinkedList(IEnumerable <T> collection, IComparer <T> comparer)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     _random        = new Random();
     this._comparer = comparer ?? Comparer <T> .Default;
     ReconstructFrom(collection);
 }
        /// <summary>
        /// Initialize a new instance of the <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> class that contains
        /// elements copied from the especified collection and that uses a specified comparer.
        /// </summary>
        /// <param name="collection">The collection whose elements are copied to the new <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/>.</param>
        /// <param name="comparer">The default comparer to use for compare objects.</param>
        public ReadOnlySortedSet(IEnumerable <T> collection, IComparer <T> comparer)
        {
            if (collection == null)
            {
                Thrower.ArgumentNullException(ArgumentType.collection);
            }
            this._comparer = comparer ?? Comparer <T> .Default;
            List <T> list = SetHelper <T> .GetSortedListSet(collection, this._comparer);

            this._elements = list.ToArray();
        }
 /// <summary>
 /// Creates a new instance of <see cref="T:Academy.Collections.Generic.MatrixEntryCollection`1"/> that contains
 /// elements copied from the specified collection and sorted by the specified order.
 /// </summary>
 /// <param name="collection">The collection whose elements are copied to the new <see cref="T:Academy.Collections.Generic.MatrixEntryCollection`1"/>.</param>
 /// <param name="order">The order the collection presents the entries.</param>
 /// <returns>a new instance of <see cref="T:Academy.Collections.Generic.MatrixEntryCollection`1"/> containing elements copied from the specified collection
 /// and provides the specified order.</returns>
 public static MatrixEntryCollection <T> Create(IEnumerable <MatrixEntry <T> > collection, MatrixDataOrder order)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     if (order == MatrixDataOrder.Default)
     {
         order = MatrixDataOrder.Row;
     }
     return(new EntryFixedCollection(collection, order));
 }
Example #20
0
 public static void CopyToCheck <T>(T[] array, int index, int count)
 {
     if (array == null)
     {
         Thrower.ArgumentNullException(ArgumentType.array);
     }
     if (index < 0 || index > array.Length)
     {
         Thrower.ArgumentOutOfRangeException(ArgumentType.index, string.Format(Resources.ArgumentOutOfRange_Range_G, new object[] { 0, array.Length - 1 }));
     }
     if (array.Length - index < count)
     {
         Thrower.ArgumentException(ArgumentType.index, Resources.Argument_ArrayNotLongEnought);
     }
 }
        /// <summary>
        /// Removes all the values that match the conditions defined by the specified predicate from a <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/>.
        /// </summary>
        /// <param name="match">The delegate that defines the conditions of the elements to remove.</param>
        /// <returns>The number of elements that were removed from the <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> collection.</returns>
        public int RemoveWhere(Predicate <T> match)
        {
            if (match == null)
            {
                Thrower.ArgumentNullException(ArgumentType.match);
            }
            List <T> matchesList = new List <T>(Count);

            ListWalk(x =>
            {
                if (match(x.Value))
                {
                    matchesList.Add(x.Value);
                }
                return(true);
            });
            return(matchesList.Count(InternalRemove));
        }
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                Thrower.ArgumentNullException(ArgumentType.info);
            }
            info.AddValue(SerializationString.Version, version);
            info.AddValue(SerializationString.Comparer, comparer, typeof(IEqualityComparer <T>));
            int size = (indices == null) ? 0 : indices.Length;

            info.AddValue(SerializationString.IndicesCount, size);
            if (indices != null)
            {
                T[] array = new T[Count];
                CopyTo(array, 0);
                info.AddValue(SerializationString.Data, array, typeof(T[]));
            }
        }
 /// <summary>
 /// Determines whether an element is in the <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> by searching every element that matches the specified 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 first 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"/>.</returns>
 public bool Contains(T value, Predicate <T> match)
 {
     if (match == null)
     {
         Thrower.ArgumentNullException(ArgumentType.match);
     }
     if (IsInRange(value))
     {
         Node current = _head;
         Node node    = null;
         for (int i = _head.Count - 1; i >= 0; i--)
         {
             while (current.Nodes[i] != null && IsInRange(current.Nodes[i].Value))
             {
                 int results = this._comparer.Compare(current.Nodes[i].Value, value);
                 if (results < 0)
                 {
                     current = current.Nodes[i];
                 }
                 else
                 {
                     if (results == 0)
                     {
                         if (match(current.Nodes[i].Value))
                         {
                             return(true);
                         }
                         node = current.Nodes[i];
                     }
                     break;
                 }
             }
         }
         while ((node != null) && (this._comparer.Compare(node.Value, value) == 0))
         {
             if (match(node.Value))
             {
                 return(true);
             }
             node = node.Nodes[0];
         }
     }
     return(false);
 }
 /// <summary>
 /// Implements the <see cref="T:System.Runtime.Serialization.ISerializable"/> interface and returns the data that you must have to serialize an <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> object.
 /// </summary>
 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that contains the information that is required to serialize the <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> object.</param>
 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> structure that contains the source and destination of the serialized stream associated with the  <see cref="T:Academy.Collections.Generic.SortedLinkedList`1"/> object.</param>
 protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         Thrower.ArgumentNullException(ArgumentType.info);
     }
     info.AddValue(SerializationString.Version, _version);
     info.AddValue(SerializationString.Count, _count);
     info.AddValue(SerializationString.Comparer, _comparer, typeof(IComparer <T>));
     if (_count != 0)
     {
         T[] local = new T[Count];
         int index = 0;
         foreach (T item in this)
         {
             local[index++] = item;
         }
         info.AddValue(SerializationString.Data, local, typeof(T[]));
     }
 }
Example #25
0
            public void FillWith(IEnumerable <T> collection)
            {
                if (collection == null)
                {
                    Thrower.ArgumentNullException(ArgumentType.collection);
                }
                int num = 0;

                if (isRow)
                {
                    foreach (var item in collection.Take(matrix.colDim))
                    {
                        matrix.DirectlySet(containedIndex, num++, item);
                    }
                }
                else
                {
                    foreach (var item in collection.Take(matrix.rowDim))
                    {
                        matrix.DirectlySet(num++, containedIndex, item);
                    }
                }
            }
Example #26
0
 public static void CopyToCheck(Array array, int index, int count)
 {
     if (array == null)
     {
         Thrower.ArgumentNullException(ArgumentType.array);
     }
     if (array.Rank != 1)
     {
         Thrower.ArgumentException(ArgumentType.array, Resources.Argument_ArrayRank);
     }
     if (array.GetLowerBound(0) != 0)
     {
         Thrower.ArgumentException(ArgumentType.array, Resources.Argument_LowerBoundArrayNotZero);
     }
     if (index < 0 || index > array.Length)
     {
         Thrower.ArgumentOutOfRangeException(ArgumentType.index, string.Format(Resources.ArgumentOutOfRange_Range_G, new object[] { 0, array.Length - 1 }));
     }
     if ((array.Length - index) < count)
     {
         Thrower.ArgumentException(ArgumentType.empty, Resources.Argument_ArrayNotLongEnought);
     }
 }
        /// <summary>
        /// Determines whether the current <see cref="T:Academy.Collections.Generic.ReadOnlySortedSet`1"/> is a superset 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 superset of <paramref name="other"/>; otherwise, false.</returns>
        public bool IsSupersetOf(IEnumerable <T> other)
        {
            if (other == null)
            {
                Thrower.ArgumentNullException(ArgumentType.other);
            }
            if (CollectionHelper.IsWellKnownCollection(other, out int num))
            {
                if (num == 0)
                {
                    return(true);
                }
                if (SetHelper <T> .IsWellKnownSet(other))
                {
                    if (this.Count < num)
                    {
                        return(false);
                    }
                }
            }
            ICommonSortedSet <T> sortedset = SetHelper <T> .GetSortedSet(other);

            if ((sortedset == null) || !AreEqualComparers(this._comparer, sortedset.Comparer))
            {
                return(this.ContainsSequence(other));
            }
            ReadOnlySortedSet <T> subset = this.GetViewBetween(sortedset.MinValue, sortedset.MaxValue);

            foreach (T item in sortedset)
            {
                if (!subset.Contains(item))
                {
                    return(false);
                }
            }
            return(true);
        }
 /// <summary>
 /// Initialize a new instance of the <see cref="T:Academy.Collections.Generic.PriorityQueue`1"/> class that contains
 /// elements copied from the especified collection and uses the specified comparer.
 /// </summary>
 /// <param name="collection">The collection whose elements are copied to the new <see cref="T:Academy.Collections.Generic.PriorityQueue`1"/>.</param>
 /// <param name="comparer">The default comparer to use for compare objects.</param>
 public PriorityQueue(IEnumerable <T> collection, IComparer <T> comparer)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     if (comparer == null)
     {
         comparer = Comparer <T> .Default;
     }
     _comparer = comparer;
     if (collection is PriorityQueue <T> heap && _comparer.Equals(heap.Comparer))
     {
         _elements     = heap._elements.Clone() as T[];
         _currentIndex = heap._currentIndex;
     }
     else
     {
         if (!CollectionHelper.IsWellKnownCollection(collection, out int num))
         {
             num = DefaultCapacity;
         }
         _elements     = new T[num + 1];
         _comparer     = comparer;
         _currentIndex = 1;
         _elements[0]  = default(T);
         using (IEnumerator <T> enumerator = collection.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 Enqueue(enumerator.Current);
             }
         }
         TrimExcess();
     }
 }
Example #29
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:Academy.Collections.Generic.EndlessQueue`1"/>
 /// class that contains elements copied from the specified collection.
 /// </summary>
 /// <param name="collection">The collection whose elements are copied to the <see cref="T:Academy.Collections.Generic.EndlessQueue`1"/>.</param>
 public EndlessQueue(IEnumerable <T> collection)
 {
     if (collection == null)
     {
         Thrower.ArgumentNullException(ArgumentType.collection);
     }
     if (!CollectionHelper.IsWellKnownCollection(collection, out int size))
     {
         size = DefSize;
     }
     this.head  = 0;
     this.tail  = 0;
     this.items = new T[DefSize];
     this.count = 0;
     foreach (var item in collection)
     {
         if (this.Count == Capacity)
         {
             Capacity = Capacity * 2;
         }
         Enqueue(item);
     }
     Capacity = Count;
 }