Ejemplo n.º 1
0
            /// <summary>
            /// Modifies the current set so that it contains all elements that are present in both the current set and in the specified collection.
            /// </summary>
            /// <param name="other">The collection to compare to the current set.</param>
            public void UnionWith(IEnumerable <T> other)
            {
                var result = ImmutableHashSet <T> .Union(other, this.Origin);

                this.Apply(result);
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="DebuggerProxy"/> class.
 /// </summary>
 /// <param name="set">The collection to display in the debugger</param>
 public DebuggerProxy(ImmutableHashSet <T> set)
 {
     Requires.NotNull(set, "set");
     this.set = set;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Determines whether the current set overlaps with the specified collection.
 /// </summary>
 /// <param name="other">The collection to compare to the current set.</param>
 /// <returns>true if the current set and other share at least one common element; otherwise, false.</returns>
 public bool Overlaps(IEnumerable <T> other)
 {
     return(ImmutableHashSet <T> .Overlaps(other, this.Origin));
 }
Ejemplo n.º 4
0
            /// <summary>
            /// Modifies the current set so that it contains only elements that are present either in the current set or in the specified collection, but not both.
            /// </summary>
            /// <param name="other">The collection to compare to the current set.</param>
            public void SymmetricExceptWith(IEnumerable <T> other)
            {
                var result = ImmutableHashSet <T> .SymmetricExcept(other, this.Origin);

                this.Apply(result);
            }
Ejemplo n.º 5
0
            /// <summary>
            /// Modifies the current set so that it contains only elements that are also in a specified collection.
            /// </summary>
            /// <param name="other">The collection to compare to the current set.</param>
            public void IntersectWith(IEnumerable <T> other)
            {
                var result = ImmutableHashSet <T> .Intersect(other, this.Origin);

                this.Apply(result);
            }
Ejemplo n.º 6
0
 /// <summary>
 /// Determines whether the current set 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 set is a superset of other; otherwise, false.</returns>
 public bool IsSupersetOf(IEnumerable <T> other)
 {
     return(ImmutableHashSet <T> .IsSupersetOf(other, this.Origin));
 }
Ejemplo n.º 7
0
            /// <summary>
            /// Removes all elements in the specified collection from the current set.
            /// </summary>
            /// <param name="other">The collection of items to remove from the set.</param>
            public void ExceptWith(IEnumerable <T> other)
            {
                var result = ImmutableHashSet <T> .Except(other, _equalityComparer, _root);

                this.Apply(result);
            }
Ejemplo n.º 8
0
 /// <summary>
 /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value.
 /// </summary>
 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
 /// <returns>
 /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false.
 /// </returns>
 public bool Contains(T item)
 {
     return(ImmutableHashSet <T> .Contains(item, this.Origin));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableHashSetDebuggerProxy{T}"/> class.
 /// </summary>
 /// <param name="set">The collection to display in the debugger</param>
 public ImmutableHashSetDebuggerProxy(ImmutableHashSet <T> set)
 {
     Requires.NotNull(set, nameof(set));
     _set = set;
 }
        public static ImmutableHashSet <T> AddRange <T>(this ImmutableHashSet <T> set1, ImmutableHashSet <T> set2)
        {
            using var builder = PooledHashSet <T> .GetInstance();

            foreach (var item in set1)
            {
                builder.Add(item);
            }

            foreach (var item in set2)
            {
                builder.Add(item);
            }

            if (builder.Count == set1.Count)
            {
                return(set1);
            }

            if (builder.Count == set2.Count)
            {
                return(set2);
            }

            return(builder.ToImmutable());
        }
        public static ImmutableHashSet <T> IntersectSet <T>(this ImmutableHashSet <T> set1, ImmutableHashSet <T> set2)
        {
            if (set1.IsEmpty || set2.IsEmpty)
            {
                return(ImmutableHashSet <T> .Empty);
            }
            else if (set1.Count == 1)
            {
                return(set2.Contains(set1.First()) ? set1 : ImmutableHashSet <T> .Empty);
            }
            else if (set2.Count == 1)
            {
                return(set1.Contains(set2.First()) ? set2 : ImmutableHashSet <T> .Empty);
            }

            using var builder = PooledHashSet <T> .GetInstance();

            foreach (var item in set1)
            {
                if (set2.Contains(item))
                {
                    builder.Add(item);
                }
            }

            if (builder.Count == set1.Count)
            {
                return(set1);
            }
            else if (builder.Count == set2.Count)
            {
                return(set2);
            }

            return(builder.ToImmutable());
        }