Ejemplo n.º 1
0
        /// <inheritdoc />
        public void IntersectWith(IEnumerable <IDisposable> other)
        {
            ISetContracts.IntersectWith(this, other);

            if (this.IsDisposed)
            {
                return;
            }

            this.disposables.IntersectWith(other);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides an implementation of <see cref="ISet{T}.IntersectWith" />.
        /// </summary>
        /// <typeparam name="T">The type of values in the collections.</typeparam>
        /// <param name="source">The source collection that is implementing <see cref="ISet{T}" />.</param>
        /// <param name="other">The other enumerable.</param>
        /// <param name="comparer">The comparer.</param>
        /// <remarks>
        /// From <see href="https://msdn.microsoft.com/en-us/library/dd394889(v=vs.110).aspx" />;
        /// Modifies the current set so that it contains only elements that are also in a specified collection.
        /// </remarks>
        public static void IntersectWith <T>(ISet <T> source, IEnumerable <T> other, IEqualityComparer <T> comparer)
        {
            Contracts.Requires.That(source != null);
            Contracts.Requires.That(comparer != null);
            ISetContracts.IntersectWith(source, other);

            if (source.IsReadOnly)
            {
                return;
            }

            IntersectWith(source, other as HashSet <T> ?? new HashSet <T>(other, comparer));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Provides an implementation of <see cref="ISet{T}.IntersectWith"/>.
        /// </summary>
        /// <typeparam name="T">The type of values in the collections.</typeparam>
        /// <param name="source">The source collection that is implementing <see cref="ISet{T}"/>.</param>
        /// <param name="other">The other enumerable.</param>
        /// <remarks>
        /// From <see href="https://msdn.microsoft.com/en-us/library/dd394889(v=vs.110).aspx"/>;
        /// Modifies the current set so that it contains only elements that are also in a specified collection.
        /// </remarks>
        public static void IntersectWith <T>(ISet <T> source, HashSet <T> other)
        {
            Contracts.Requires.That(source != null);
            ISetContracts.IntersectWith(source, other);

            if (source.IsReadOnly)
            {
                return;
            }

            List <T> valuesToRemove = new List <T>();

            foreach (T value in source)
            {
                if (!other.Contains(value))
                {
                    valuesToRemove.Add(value);
                }
            }

            source.RemoveMany(valuesToRemove);
        }