Guest User

Untitled

a guest
Jun 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 44.22 KB | None | 0 0
  1. // Type: System.Collections.Generic.HashSet`1
  2. // Assembly: System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  3. // Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Core.dll
  4.  
  5. using System;
  6. using System.Collections;
  7. using System.Diagnostics;
  8. using System.Runtime.Serialization;
  9. using System.Security;
  10. using System.Security.Permissions;
  11.  
  12. namespace System.Collections.Generic
  13. {
  14.   /// <summary>
  15.   /// Represents a set of values.
  16.   /// </summary>
  17.   /// <typeparam name="T">The type of elements in the hast set.</typeparam>
  18.   [DebuggerDisplay("Count = {Count}")]
  19.   [DebuggerTypeProxy(typeof (HashSetDebugView<>))]
  20.   [Serializable]
  21.   [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
  22.   public class HashSet<T> : ISerializable, IDeserializationCallback, ISet<T>, ICollection<T>, IEnumerable<T>, IEnumerable
  23.   {
  24.     private const int Lower31BitMask = 2147483647;
  25.     private const int GrowthFactor = 2;
  26.     private const int StackAllocThreshold = 100;
  27.     private const int ShrinkThreshold = 3;
  28.     private const string CapacityName = "Capacity";
  29.     private const string ElementsName = "Elements";
  30.     private const string ComparerName = "Comparer";
  31.     private const string VersionName = "Version";
  32.     private int[] m_buckets;
  33.     private HashSet<T>.Slot[] m_slots;
  34.     private int m_count;
  35.     private int m_lastIndex;
  36.     private int m_freeList;
  37.     private IEqualityComparer<T> m_comparer;
  38.     private int m_version;
  39.     private SerializationInfo m_siInfo;
  40.  
  41.     /// <summary>
  42.     /// Gets the number of elements that are contained in a set.
  43.     /// </summary>
  44.     ///
  45.     /// <returns>
  46.     /// The number of elements that are contained in the set.
  47.     /// </returns>
  48.     public int Count
  49.     {
  50.       get
  51.       {
  52.         return this.m_count;
  53.       }
  54.     }
  55.  
  56.     bool ICollection<T>.IsReadOnly
  57.     {
  58.       get
  59.       {
  60.         return false;
  61.       }
  62.     }
  63.  
  64.     /// <summary>
  65.     /// Gets the <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> object that is used to determine equality for the values in the set.
  66.     /// </summary>
  67.     ///
  68.     /// <returns>
  69.     /// The <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> object that is used to determine equality for the values in the set.
  70.     /// </returns>
  71.     public IEqualityComparer<T> Comparer
  72.     {
  73.       get
  74.       {
  75.         return this.m_comparer;
  76.       }
  77.     }
  78.  
  79.     /// <summary>
  80.     /// Initializes a new instance of the <see cref="T:System.Collections.Generic.HashSet`1"/> class that is empty and uses the default equality comparer for the set type.
  81.     /// </summary>
  82.     public HashSet()
  83.       : this((IEqualityComparer<T>) EqualityComparer<T>.Default)
  84.     {
  85.     }
  86.  
  87.     /// <summary>
  88.     /// Initializes a new instance of the <see cref="T:System.Collections.Generic.HashSet`1"/> class that is empty and uses the specified equality comparer for the set type.
  89.     /// </summary>
  90.     /// <param name="comparer">The <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> implementation to use when comparing values in the set, or null to use the default <see cref="T:System.Collections.Generic.EqualityComparer`1"/> implementation for the set type.</param>
  91.     public HashSet(IEqualityComparer<T> comparer)
  92.     {
  93.       if (comparer == null)
  94.         comparer = (IEqualityComparer<T>) EqualityComparer<T>.Default;
  95.       this.m_comparer = comparer;
  96.       this.m_lastIndex = 0;
  97.       this.m_count = 0;
  98.       this.m_freeList = -1;
  99.       this.m_version = 0;
  100.     }
  101.  
  102.     /// <summary>
  103.     /// Initializes a new instance of the <see cref="T:System.Collections.Generic.HashSet`1"/> class that uses the default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
  104.     /// </summary>
  105.     /// <param name="collection">The collection whose elements are copied to the new set.</param><exception cref="T:System.ArgumentNullException"><paramref name="collection"/> is null.</exception>
  106.     public HashSet(IEnumerable<T> collection)
  107.       : this(collection, (IEqualityComparer<T>) EqualityComparer<T>.Default)
  108.     {
  109.     }
  110.  
  111.     /// <summary>
  112.     /// Initializes a new instance of the <see cref="T:System.Collections.Generic.HashSet`1"/> class that uses the specified equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
  113.     /// </summary>
  114.     /// <param name="collection">The collection whose elements are copied to the new set.</param><param name="comparer">The <see cref="T:System.Collections.Generic.IEqualityComparer`1"/> implementation to use when comparing values in the set, or null to use the default <see cref="T:System.Collections.Generic.EqualityComparer`1"/> implementation for the set type.</param><exception cref="T:System.ArgumentNullException"><paramref name="collection"/> is null.</exception>
  115.     public HashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
  116.       : this(comparer)
  117.     {
  118.       if (collection == null)
  119.         throw new ArgumentNullException("collection");
  120.       int capacity = 0;
  121.       ICollection<T> collection1 = collection as ICollection<T>;
  122.       if (collection1 != null)
  123.         capacity = collection1.Count;
  124.       this.Initialize(capacity);
  125.       this.UnionWith(collection);
  126.       if ((this.m_count != 0 || this.m_slots.Length <= System.Collections.Generic.HashHelpers.GetMinPrime()) && (this.m_count <= 0 || this.m_slots.Length / this.m_count <= 3))
  127.         return;
  128.       this.TrimExcess();
  129.     }
  130.  
  131.     /// <summary>
  132.     /// Initializes a new instance of the <see cref="T:System.Collections.Generic.HashSet`1"/> class with serialized data.
  133.     /// </summary>
  134.     /// <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo"/> object that contains the information required to serialize the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext"/> structure that contains the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param>
  135.     protected HashSet(SerializationInfo info, StreamingContext context)
  136.     {
  137.       this.m_siInfo = info;
  138.     }
  139.  
  140.     void ICollection<T>.Add(T item)
  141.     {
  142.       this.AddIfNotPresent(item);
  143.     }
  144.  
  145.     /// <summary>
  146.     /// Removes all elements from a <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  147.     /// </summary>
  148.     public void Clear()
  149.     {
  150.       if (this.m_lastIndex > 0)
  151.       {
  152.         Array.Clear((Array) this.m_slots, 0, this.m_lastIndex);
  153.         Array.Clear((Array) this.m_buckets, 0, this.m_buckets.Length);
  154.         this.m_lastIndex = 0;
  155.         this.m_count = 0;
  156.         this.m_freeList = -1;
  157.       }
  158.       ++this.m_version;
  159.     }
  160.  
  161.     /// <summary>
  162.     /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object contains the specified element.
  163.     /// </summary>
  164.     ///
  165.     /// <returns>
  166.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object contains the specified element; otherwise, false.
  167.     /// </returns>
  168.     /// <param name="item">The element to locate in the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param>
  169.     public bool Contains(T item)
  170.     {
  171.       if (this.m_buckets != null)
  172.       {
  173.         int hashCode = this.InternalGetHashCode(item);
  174.         for (int index = this.m_buckets[hashCode % this.m_buckets.Length] - 1; index >= 0; index = this.m_slots[index].next)
  175.         {
  176.           if (this.m_slots[index].hashCode == hashCode && this.m_comparer.Equals(this.m_slots[index].value, item))
  177.             return true;
  178.         }
  179.       }
  180.       return false;
  181.     }
  182.  
  183.     /// <summary>
  184.     /// Copies the elements of a <see cref="T:System.Collections.Generic.HashSet`1"/> object to an array, starting at the specified array index.
  185.     /// </summary>
  186.     /// <param name="array">The one-dimensional array that is the destination of the elements copied from the <see cref="T:System.Collections.Generic.HashSet`1"/> object. The array must have zero-based indexing.</param><param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0.</exception><exception cref="T:System.ArgumentException"><paramref name="arrayIndex"/> is greater than the length of the destination <paramref name="array"/>.-or-<paramref name="count"/> is larger than the size of the destination <paramref name="array"/>.</exception>
  187.     public void CopyTo(T[] array, int arrayIndex)
  188.     {
  189.       this.CopyTo(array, arrayIndex, this.m_count);
  190.     }
  191.  
  192.     /// <summary>
  193.     /// Removes the specified element from a <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  194.     /// </summary>
  195.     ///
  196.     /// <returns>
  197.     /// true if the element is successfully found and removed; otherwise, false.  This method returns false if <paramref name="item"/> is not found in the <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  198.     /// </returns>
  199.     /// <param name="item">The element to remove.</param>
  200.     public bool Remove(T item)
  201.     {
  202.       if (this.m_buckets != null)
  203.       {
  204.         int hashCode = this.InternalGetHashCode(item);
  205.         int index1 = hashCode % this.m_buckets.Length;
  206.         int index2 = -1;
  207.         for (int index3 = this.m_buckets[index1] - 1; index3 >= 0; index3 = this.m_slots[index3].next)
  208.         {
  209.           if (this.m_slots[index3].hashCode == hashCode && this.m_comparer.Equals(this.m_slots[index3].value, item))
  210.           {
  211.             if (index2 < 0)
  212.               this.m_buckets[index1] = this.m_slots[index3].next + 1;
  213.             else
  214.               this.m_slots[index2].next = this.m_slots[index3].next;
  215.             this.m_slots[index3].hashCode = -1;
  216.             this.m_slots[index3].value = default (T);
  217.             this.m_slots[index3].next = this.m_freeList;
  218.             --this.m_count;
  219.             ++this.m_version;
  220.             if (this.m_count == 0)
  221.             {
  222.               this.m_lastIndex = 0;
  223.               this.m_freeList = -1;
  224.             }
  225.             else
  226.               this.m_freeList = index3;
  227.             return true;
  228.           }
  229.           else
  230.             index2 = index3;
  231.         }
  232.       }
  233.       return false;
  234.     }
  235.  
  236.     /// <summary>
  237.     /// Returns an enumerator that iterates through a <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  238.     /// </summary>
  239.     ///
  240.     /// <returns>
  241.     /// A <see cref="T:System.Collections.Generic.HashSet`1.Enumerator"/> object for the <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  242.     /// </returns>
  243.     public HashSet<T>.Enumerator GetEnumerator()
  244.     {
  245.       return new HashSet<T>.Enumerator(this);
  246.     }
  247.  
  248.     IEnumerator<T> IEnumerable<T>.GetEnumerator()
  249.     {
  250.       return (IEnumerator<T>) new HashSet<T>.Enumerator(this);
  251.     }
  252.  
  253.     IEnumerator IEnumerable.GetEnumerator()
  254.     {
  255.       return (IEnumerator) new HashSet<T>.Enumerator(this);
  256.     }
  257.  
  258.     /// <summary>
  259.     /// Implements the <see cref="T:System.Runtime.Serialization.ISerializable"/> interface and returns the data needed to serialize a <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  260.     /// </summary>
  261.     /// <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo"/> object that contains the information required to serialize the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext"/> structure that contains the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="info"/> is null.</exception><filterpriority>2</filterpriority>
  262.     [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  263.     public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
  264.     {
  265.       if (info == null)
  266.         throw new ArgumentNullException("info");
  267.       info.AddValue("Version", this.m_version);
  268.       info.AddValue("Comparer", (object) this.m_comparer, typeof (IEqualityComparer<T>));
  269.       info.AddValue("Capacity", this.m_buckets == null ? 0 : this.m_buckets.Length);
  270.       if (this.m_buckets == null)
  271.         return;
  272.       T[] array = new T[this.m_count];
  273.       this.CopyTo(array);
  274.       info.AddValue("Elements", (object) array, typeof (T[]));
  275.     }
  276.  
  277.     /// <summary>
  278.     /// Implements the <see cref="T:System.Runtime.Serialization.ISerializable"/> interface and raises the deserialization event when the deserialization is complete.
  279.     /// </summary>
  280.     /// <param name="sender">The source of the deserialization event.</param><exception cref="T:System.Runtime.Serialization.SerializationException">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> object associated with the current <see cref="T:System.Collections.Generic.HashSet`1"/> object is invalid.</exception><filterpriority>2</filterpriority>
  281.     public virtual void OnDeserialization(object sender)
  282.     {
  283.       if (this.m_siInfo == null)
  284.         return;
  285.       int int32 = this.m_siInfo.GetInt32("Capacity");
  286.       this.m_comparer = (IEqualityComparer<T>) this.m_siInfo.GetValue("Comparer", typeof (IEqualityComparer<T>));
  287.       this.m_freeList = -1;
  288.       if (int32 != 0)
  289.       {
  290.         this.m_buckets = new int[int32];
  291.         this.m_slots = new HashSet<T>.Slot[int32];
  292.         T[] objArray = (T[]) this.m_siInfo.GetValue("Elements", typeof (T[]));
  293.         if (objArray == null)
  294.           throw new SerializationException(SR.GetString("Serialization_MissingKeys"));
  295.         for (int index = 0; index < objArray.Length; ++index)
  296.           this.AddIfNotPresent(objArray[index]);
  297.       }
  298.       else
  299.         this.m_buckets = (int[]) null;
  300.       this.m_version = this.m_siInfo.GetInt32("Version");
  301.       this.m_siInfo = (SerializationInfo) null;
  302.     }
  303.  
  304.     /// <summary>
  305.     /// Adds the specified element to a set.
  306.     /// </summary>
  307.     ///
  308.     /// <returns>
  309.     /// true if the element is added to the <see cref="T:System.Collections.Generic.HashSet`1"/> object; false if the element is already present.
  310.     /// </returns>
  311.     /// <param name="item">The element to add to the set.</param>
  312.     public bool Add(T item)
  313.     {
  314.       return this.AddIfNotPresent(item);
  315.     }
  316.  
  317.     /// <summary>
  318.     /// Modifies the current <see cref="T:System.Collections.Generic.HashSet`1"/> object to contain all elements that are present in both itself and in the specified collection.
  319.     /// </summary>
  320.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  321.     public void UnionWith(IEnumerable<T> other)
  322.     {
  323.       if (other == null)
  324.         throw new ArgumentNullException("other");
  325.       foreach (T obj in other)
  326.         this.AddIfNotPresent(obj);
  327.     }
  328.  
  329.     /// <summary>
  330.     /// Modifies the current <see cref="T:System.Collections.Generic.HashSet`1"/> object to contain only elements that are present in that object and in the specified collection.
  331.     /// </summary>
  332.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  333.     [SecurityCritical]
  334.     public void IntersectWith(IEnumerable<T> other)
  335.     {
  336.       if (other == null)
  337.         throw new ArgumentNullException("other");
  338.       if (this.m_count == 0)
  339.         return;
  340.       ICollection<T> collection = other as ICollection<T>;
  341.       if (collection != null)
  342.       {
  343.         if (collection.Count == 0)
  344.         {
  345.           this.Clear();
  346.           return;
  347.         }
  348.         else
  349.         {
  350.           HashSet<T> hashSet = other as HashSet<T>;
  351.           if (hashSet != null && HashSet<T>.AreEqualityComparersEqual(this, hashSet))
  352.           {
  353.             this.IntersectWithHashSetWithSameEC(hashSet);
  354.             return;
  355.           }
  356.         }
  357.       }
  358.       this.IntersectWithEnumerable(other);
  359.     }
  360.  
  361.     /// <summary>
  362.     /// Removes all elements in the specified collection from the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  363.     /// </summary>
  364.     /// <param name="other">The collection of items to remove from the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  365.     public void ExceptWith(IEnumerable<T> other)
  366.     {
  367.       if (other == null)
  368.         throw new ArgumentNullException("other");
  369.       if (this.m_count == 0)
  370.         return;
  371.       if (other == this)
  372.       {
  373.         this.Clear();
  374.       }
  375.       else
  376.       {
  377.         foreach (T obj in other)
  378.           this.Remove(obj);
  379.       }
  380.     }
  381.  
  382.     /// <summary>
  383.     /// Modifies the current <see cref="T:System.Collections.Generic.HashSet`1"/> object to contain only elements that are present either in that object or in the specified collection, but not both.
  384.     /// </summary>
  385.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  386.     [SecurityCritical]
  387.     public void SymmetricExceptWith(IEnumerable<T> other)
  388.     {
  389.       if (other == null)
  390.         throw new ArgumentNullException("other");
  391.       if (this.m_count == 0)
  392.         this.UnionWith(other);
  393.       else if (other == this)
  394.       {
  395.         this.Clear();
  396.       }
  397.       else
  398.       {
  399.         HashSet<T> hashSet = other as HashSet<T>;
  400.         if (hashSet != null && HashSet<T>.AreEqualityComparersEqual(this, hashSet))
  401.           this.SymmetricExceptWithUniqueHashSet(hashSet);
  402.         else
  403.           this.SymmetricExceptWithEnumerable(other);
  404.       }
  405.     }
  406.  
  407.     /// <summary>
  408.     /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object is a subset of the specified collection.
  409.     /// </summary>
  410.     ///
  411.     /// <returns>
  412.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object is a subset of <paramref name="other"/>; otherwise, false.
  413.     /// </returns>
  414.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  415.     [SecurityCritical]
  416.     public bool IsSubsetOf(IEnumerable<T> other)
  417.     {
  418.       if (other == null)
  419.         throw new ArgumentNullException("other");
  420.       if (this.m_count == 0)
  421.         return true;
  422.       HashSet<T> hashSet = other as HashSet<T>;
  423.       if (hashSet != null && HashSet<T>.AreEqualityComparersEqual(this, hashSet))
  424.       {
  425.         if (this.m_count > hashSet.Count)
  426.           return false;
  427.         else
  428.           return this.IsSubsetOfHashSetWithSameEC(hashSet);
  429.       }
  430.       else
  431.       {
  432.         HashSet<T>.ElementCount elementCount = this.CheckUniqueAndUnfoundElements(other, false);
  433.         if (elementCount.uniqueCount == this.m_count)
  434.           return elementCount.unfoundCount >= 0;
  435.         else
  436.           return false;
  437.       }
  438.     }
  439.  
  440.     /// <summary>
  441.     /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object is a proper subset of the specified collection.
  442.     /// </summary>
  443.     ///
  444.     /// <returns>
  445.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object is a proper subset of <paramref name="other"/>; otherwise, false.
  446.     /// </returns>
  447.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  448.     [SecurityCritical]
  449.     public bool IsProperSubsetOf(IEnumerable<T> other)
  450.     {
  451.       if (other == null)
  452.         throw new ArgumentNullException("other");
  453.       ICollection<T> collection = other as ICollection<T>;
  454.       if (collection != null)
  455.       {
  456.         if (this.m_count == 0)
  457.           return collection.Count > 0;
  458.         HashSet<T> hashSet = other as HashSet<T>;
  459.         if (hashSet != null && HashSet<T>.AreEqualityComparersEqual(this, hashSet))
  460.         {
  461.           if (this.m_count >= hashSet.Count)
  462.             return false;
  463.           else
  464.             return this.IsSubsetOfHashSetWithSameEC(hashSet);
  465.         }
  466.       }
  467.       HashSet<T>.ElementCount elementCount = this.CheckUniqueAndUnfoundElements(other, false);
  468.       if (elementCount.uniqueCount == this.m_count)
  469.         return elementCount.unfoundCount > 0;
  470.       else
  471.         return false;
  472.     }
  473.  
  474.     /// <summary>
  475.     /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object is a superset of the specified collection.
  476.     /// </summary>
  477.     ///
  478.     /// <returns>
  479.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object is a superset of <paramref name="other"/>; otherwise, false.
  480.     /// </returns>
  481.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  482.     public bool IsSupersetOf(IEnumerable<T> other)
  483.     {
  484.       if (other == null)
  485.         throw new ArgumentNullException("other");
  486.       ICollection<T> collection = other as ICollection<T>;
  487.       if (collection != null)
  488.       {
  489.         if (collection.Count == 0)
  490.           return true;
  491.         HashSet<T> set2 = other as HashSet<T>;
  492.         if (set2 != null && HashSet<T>.AreEqualityComparersEqual(this, set2) && set2.Count > this.m_count)
  493.           return false;
  494.       }
  495.       return this.ContainsAllElements(other);
  496.     }
  497.  
  498.     /// <summary>
  499.     /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object is a proper superset of the specified collection.
  500.     /// </summary>
  501.     ///
  502.     /// <returns>
  503.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object is a proper superset of <paramref name="other"/>; otherwise, false.
  504.     /// </returns>
  505.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object. </param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  506.     [SecurityCritical]
  507.     public bool IsProperSupersetOf(IEnumerable<T> other)
  508.     {
  509.       if (other == null)
  510.         throw new ArgumentNullException("other");
  511.       if (this.m_count == 0)
  512.         return false;
  513.       ICollection<T> collection = other as ICollection<T>;
  514.       if (collection != null)
  515.       {
  516.         if (collection.Count == 0)
  517.           return true;
  518.         HashSet<T> set2 = other as HashSet<T>;
  519.         if (set2 != null && HashSet<T>.AreEqualityComparersEqual(this, set2))
  520.         {
  521.           if (set2.Count >= this.m_count)
  522.             return false;
  523.           else
  524.             return this.ContainsAllElements((IEnumerable<T>) set2);
  525.         }
  526.       }
  527.       HashSet<T>.ElementCount elementCount = this.CheckUniqueAndUnfoundElements(other, true);
  528.       if (elementCount.uniqueCount < this.m_count)
  529.         return elementCount.unfoundCount == 0;
  530.       else
  531.         return false;
  532.     }
  533.  
  534.     /// <summary>
  535.     /// Determines whether the current <see cref="T:System.Collections.Generic.HashSet`1"/> object and a specified collection share common elements.
  536.     /// </summary>
  537.     ///
  538.     /// <returns>
  539.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object and <paramref name="other"/> share at least one common element; otherwise, false.
  540.     /// </returns>
  541.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  542.     public bool Overlaps(IEnumerable<T> other)
  543.     {
  544.       if (other == null)
  545.         throw new ArgumentNullException("other");
  546.       if (this.m_count == 0)
  547.         return false;
  548.       foreach (T obj in other)
  549.       {
  550.         if (this.Contains(obj))
  551.           return true;
  552.       }
  553.       return false;
  554.     }
  555.  
  556.     /// <summary>
  557.     /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object and the specified collection contain the same elements.
  558.     /// </summary>
  559.     ///
  560.     /// <returns>
  561.     /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object is equal to <paramref name="other"/>; otherwise, false.
  562.     /// </returns>
  563.     /// <param name="other">The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception>
  564.     [SecurityCritical]
  565.     public bool SetEquals(IEnumerable<T> other)
  566.     {
  567.       if (other == null)
  568.         throw new ArgumentNullException("other");
  569.       HashSet<T> set2 = other as HashSet<T>;
  570.       if (set2 != null && HashSet<T>.AreEqualityComparersEqual(this, set2))
  571.       {
  572.         if (this.m_count != set2.Count)
  573.           return false;
  574.         else
  575.           return this.ContainsAllElements((IEnumerable<T>) set2);
  576.       }
  577.       else
  578.       {
  579.         ICollection<T> collection = other as ICollection<T>;
  580.         if (collection != null && this.m_count == 0 && collection.Count > 0)
  581.           return false;
  582.         HashSet<T>.ElementCount elementCount = this.CheckUniqueAndUnfoundElements(other, true);
  583.         if (elementCount.uniqueCount == this.m_count)
  584.           return elementCount.unfoundCount == 0;
  585.         else
  586.           return false;
  587.       }
  588.     }
  589.  
  590.     /// <summary>
  591.     /// Copies the elements of a <see cref="T:System.Collections.Generic.HashSet`1"/> object to an array.
  592.     /// </summary>
  593.     /// <param name="array">The one-dimensional array that is the destination of the elements copied from the <see cref="T:System.Collections.Generic.HashSet`1"/> object. The array must have zero-based indexing.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception>
  594.     public void CopyTo(T[] array)
  595.     {
  596.       this.CopyTo(array, 0, this.m_count);
  597.     }
  598.  
  599.     /// <summary>
  600.     /// Copies the specified number of elements of a <see cref="T:System.Collections.Generic.HashSet`1"/> object to an array, starting at the specified array index.
  601.     /// </summary>
  602.     /// <param name="array">The one-dimensional array that is the destination of the elements copied from the <see cref="T:System.Collections.Generic.HashSet`1"/> object. The array must have zero-based indexing.</param><param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param><param name="count">The number of elements to copy to <paramref name="array"/>.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0.-or-<paramref name="count"/> is less than 0.</exception><exception cref="T:System.ArgumentException"><paramref name="arrayIndex"/> is greater than the length of the destination <paramref name="array"/>.-or-<paramref name="count"/> is greater than the available space from the <paramref name="index"/> to the end of the destination <paramref name="array"/>.</exception>
  603.     public void CopyTo(T[] array, int arrayIndex, int count)
  604.     {
  605.       if (array == null)
  606.         throw new ArgumentNullException("array");
  607.       if (arrayIndex < 0)
  608.         throw new ArgumentOutOfRangeException("arrayIndex", SR.GetString("ArgumentOutOfRange_NeedNonNegNum"));
  609.       if (count < 0)
  610.         throw new ArgumentOutOfRangeException("count", SR.GetString("ArgumentOutOfRange_NeedNonNegNum"));
  611.       if (arrayIndex > array.Length || count > array.Length - arrayIndex)
  612.         throw new ArgumentException(SR.GetString("Arg_ArrayPlusOffTooSmall"));
  613.       int num = 0;
  614.       for (int index = 0; index < this.m_lastIndex && num < count; ++index)
  615.       {
  616.         if (this.m_slots[index].hashCode >= 0)
  617.         {
  618.           array[arrayIndex + num] = this.m_slots[index].value;
  619.           ++num;
  620.         }
  621.       }
  622.     }
  623.  
  624.     /// <summary>
  625.     /// Removes all elements that match the conditions defined by the specified predicate from a <see cref="T:System.Collections.Generic.HashSet`1"/> collection.
  626.     /// </summary>
  627.     ///
  628.     /// <returns>
  629.     /// The number of elements that were removed from the <see cref="T:System.Collections.Generic.HashSet`1"/> collection.
  630.     /// </returns>
  631.     /// <param name="match">The <see cref="T:System.Predicate`1"/> delegate that defines the conditions of the elements to remove.</param><exception cref="T:System.ArgumentNullException"><paramref name="match"/> is null.</exception>
  632.     public int RemoveWhere(Predicate<T> match)
  633.     {
  634.       if (match == null)
  635.         throw new ArgumentNullException("match");
  636.       int num = 0;
  637.       for (int index = 0; index < this.m_lastIndex; ++index)
  638.       {
  639.         if (this.m_slots[index].hashCode >= 0)
  640.         {
  641.           T obj = this.m_slots[index].value;
  642.           if (match(obj) && this.Remove(obj))
  643.             ++num;
  644.         }
  645.       }
  646.       return num;
  647.     }
  648.  
  649.     /// <summary>
  650.     /// Sets the capacity of a <see cref="T:System.Collections.Generic.HashSet`1"/> object to the actual number of elements it contains, rounded up to a nearby, implementation-specific value.
  651.     /// </summary>
  652.     public void TrimExcess()
  653.     {
  654.       if (this.m_count == 0)
  655.       {
  656.         this.m_buckets = (int[]) null;
  657.         this.m_slots = (HashSet<T>.Slot[]) null;
  658.         ++this.m_version;
  659.       }
  660.       else
  661.       {
  662.         int prime = System.Collections.Generic.HashHelpers.GetPrime(this.m_count);
  663.         HashSet<T>.Slot[] slotArray = new HashSet<T>.Slot[prime];
  664.         int[] numArray = new int[prime];
  665.         int index1 = 0;
  666.         for (int index2 = 0; index2 < this.m_lastIndex; ++index2)
  667.         {
  668.           if (this.m_slots[index2].hashCode >= 0)
  669.           {
  670.             slotArray[index1] = this.m_slots[index2];
  671.             int index3 = slotArray[index1].hashCode % prime;
  672.             slotArray[index1].next = numArray[index3] - 1;
  673.             numArray[index3] = index1 + 1;
  674.             ++index1;
  675.           }
  676.         }
  677.         this.m_lastIndex = index1;
  678.         this.m_slots = slotArray;
  679.         this.m_buckets = numArray;
  680.         this.m_freeList = -1;
  681.       }
  682.     }
  683.  
  684.     /// <summary>
  685.     /// Returns an <see cref="T:System.Collections.IEqualityComparer"/> object that can be used for equality testing of a <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  686.     /// </summary>
  687.     ///
  688.     /// <returns>
  689.     /// An <see cref="T:System.Collections.IEqualityComparer"/> object that can be used for deep equality testing of the <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  690.     /// </returns>
  691.     public static IEqualityComparer<HashSet<T>> CreateSetComparer()
  692.     {
  693.       return (IEqualityComparer<HashSet<T>>) new HashSetEqualityComparer<T>();
  694.     }
  695.  
  696.     private void Initialize(int capacity)
  697.     {
  698.       int prime = System.Collections.Generic.HashHelpers.GetPrime(capacity);
  699.       this.m_buckets = new int[prime];
  700.       this.m_slots = new HashSet<T>.Slot[prime];
  701.     }
  702.  
  703.     private void IncreaseCapacity()
  704.     {
  705.       int min = this.m_count * 2;
  706.       if (min < 0)
  707.         min = this.m_count;
  708.       int prime = System.Collections.Generic.HashHelpers.GetPrime(min);
  709.       if (prime <= this.m_count)
  710.         throw new ArgumentException(SR.GetString("Arg_HSCapacityOverflow"));
  711.       HashSet<T>.Slot[] slotArray = new HashSet<T>.Slot[prime];
  712.       if (this.m_slots != null)
  713.         Array.Copy((Array) this.m_slots, 0, (Array) slotArray, 0, this.m_lastIndex);
  714.       int[] numArray = new int[prime];
  715.       for (int index1 = 0; index1 < this.m_lastIndex; ++index1)
  716.       {
  717.         int index2 = slotArray[index1].hashCode % prime;
  718.         slotArray[index1].next = numArray[index2] - 1;
  719.         numArray[index2] = index1 + 1;
  720.       }
  721.       this.m_slots = slotArray;
  722.       this.m_buckets = numArray;
  723.     }
  724.  
  725.     private bool AddIfNotPresent(T value)
  726.     {
  727.       if (this.m_buckets == null)
  728.         this.Initialize(0);
  729.       int hashCode = this.InternalGetHashCode(value);
  730.       int index1 = hashCode % this.m_buckets.Length;
  731.       for (int index2 = this.m_buckets[hashCode % this.m_buckets.Length] - 1; index2 >= 0; index2 = this.m_slots[index2].next)
  732.       {
  733.         if (this.m_slots[index2].hashCode == hashCode && this.m_comparer.Equals(this.m_slots[index2].value, value))
  734.           return false;
  735.       }
  736.       int index3;
  737.       if (this.m_freeList >= 0)
  738.       {
  739.         index3 = this.m_freeList;
  740.         this.m_freeList = this.m_slots[index3].next;
  741.       }
  742.       else
  743.       {
  744.         if (this.m_lastIndex == this.m_slots.Length)
  745.         {
  746.           this.IncreaseCapacity();
  747.           index1 = hashCode % this.m_buckets.Length;
  748.         }
  749.         index3 = this.m_lastIndex;
  750.         ++this.m_lastIndex;
  751.       }
  752.       this.m_slots[index3].hashCode = hashCode;
  753.       this.m_slots[index3].value = value;
  754.       this.m_slots[index3].next = this.m_buckets[index1] - 1;
  755.       this.m_buckets[index1] = index3 + 1;
  756.       ++this.m_count;
  757.       ++this.m_version;
  758.       return true;
  759.     }
  760.  
  761.     private bool ContainsAllElements(IEnumerable<T> other)
  762.     {
  763.       foreach (T obj in other)
  764.       {
  765.         if (!this.Contains(obj))
  766.           return false;
  767.       }
  768.       return true;
  769.     }
  770.  
  771.     private bool IsSubsetOfHashSetWithSameEC(HashSet<T> other)
  772.     {
  773.       foreach (T obj in this)
  774.       {
  775.         if (!other.Contains(obj))
  776.           return false;
  777.       }
  778.       return true;
  779.     }
  780.  
  781.     private void IntersectWithHashSetWithSameEC(HashSet<T> other)
  782.     {
  783.       for (int index = 0; index < this.m_lastIndex; ++index)
  784.       {
  785.         if (this.m_slots[index].hashCode >= 0)
  786.         {
  787.           T obj = this.m_slots[index].value;
  788.           if (!other.Contains(obj))
  789.             this.Remove(obj);
  790.         }
  791.       }
  792.     }
  793.  
  794.     [SecurityCritical]
  795.     private unsafe void IntersectWithEnumerable(IEnumerable<T> other)
  796.     {
  797.       int n = this.m_lastIndex;
  798.       int length = BitHelper.ToIntArrayLength(n);
  799.       BitHelper bitHelper;
  800.       if (length <= 100)
  801.       {
  802.         int* bitArrayPtr = stackalloc int[length];
  803.         bitHelper = new BitHelper(bitArrayPtr, length);
  804.       }
  805.       else
  806.         bitHelper = new BitHelper(new int[length], length);
  807.       foreach (T obj in other)
  808.       {
  809.         int bitPosition = this.InternalIndexOf(obj);
  810.         if (bitPosition >= 0)
  811.           bitHelper.MarkBit(bitPosition);
  812.       }
  813.       for (int bitPosition = 0; bitPosition < n; ++bitPosition)
  814.       {
  815.         if (this.m_slots[bitPosition].hashCode >= 0 && !bitHelper.IsMarked(bitPosition))
  816.           this.Remove(this.m_slots[bitPosition].value);
  817.       }
  818.     }
  819.  
  820.     private int InternalIndexOf(T item)
  821.     {
  822.       int hashCode = this.InternalGetHashCode(item);
  823.       for (int index = this.m_buckets[hashCode % this.m_buckets.Length] - 1; index >= 0; index = this.m_slots[index].next)
  824.       {
  825.         if (this.m_slots[index].hashCode == hashCode && this.m_comparer.Equals(this.m_slots[index].value, item))
  826.           return index;
  827.       }
  828.       return -1;
  829.     }
  830.  
  831.     private void SymmetricExceptWithUniqueHashSet(HashSet<T> other)
  832.     {
  833.       foreach (T obj in other)
  834.       {
  835.         if (!this.Remove(obj))
  836.           this.AddIfNotPresent(obj);
  837.       }
  838.     }
  839.  
  840.     [SecurityCritical]
  841.     private unsafe void SymmetricExceptWithEnumerable(IEnumerable<T> other)
  842.     {
  843.       int n = this.m_lastIndex;
  844.       int length = BitHelper.ToIntArrayLength(n);
  845.       BitHelper bitHelper1;
  846.       BitHelper bitHelper2;
  847.       if (length <= 50)
  848.       {
  849.         int* bitArrayPtr1 = stackalloc int[length];
  850.         bitHelper1 = new BitHelper(bitArrayPtr1, length);
  851.         int* bitArrayPtr2 = stackalloc int[length];
  852.         bitHelper2 = new BitHelper(bitArrayPtr2, length);
  853.       }
  854.       else
  855.       {
  856.         bitHelper1 = new BitHelper(new int[length], length);
  857.         bitHelper2 = new BitHelper(new int[length], length);
  858.       }
  859.       foreach (T obj in other)
  860.       {
  861.         int location = 0;
  862.         if (this.AddOrGetLocation(obj, out location))
  863.           bitHelper2.MarkBit(location);
  864.         else if (location < n && !bitHelper2.IsMarked(location))
  865.           bitHelper1.MarkBit(location);
  866.       }
  867.       for (int bitPosition = 0; bitPosition < n; ++bitPosition)
  868.       {
  869.         if (bitHelper1.IsMarked(bitPosition))
  870.           this.Remove(this.m_slots[bitPosition].value);
  871.       }
  872.     }
  873.  
  874.     private bool AddOrGetLocation(T value, out int location)
  875.     {
  876.       int hashCode = this.InternalGetHashCode(value);
  877.       int index1 = hashCode % this.m_buckets.Length;
  878.       for (int index2 = this.m_buckets[hashCode % this.m_buckets.Length] - 1; index2 >= 0; index2 = this.m_slots[index2].next)
  879.       {
  880.         if (this.m_slots[index2].hashCode == hashCode && this.m_comparer.Equals(this.m_slots[index2].value, value))
  881.         {
  882.           location = index2;
  883.           return false;
  884.         }
  885.       }
  886.       int index3;
  887.       if (this.m_freeList >= 0)
  888.       {
  889.         index3 = this.m_freeList;
  890.         this.m_freeList = this.m_slots[index3].next;
  891.       }
  892.       else
  893.       {
  894.         if (this.m_lastIndex == this.m_slots.Length)
  895.         {
  896.           this.IncreaseCapacity();
  897.           index1 = hashCode % this.m_buckets.Length;
  898.         }
  899.         index3 = this.m_lastIndex;
  900.         ++this.m_lastIndex;
  901.       }
  902.       this.m_slots[index3].hashCode = hashCode;
  903.       this.m_slots[index3].value = value;
  904.       this.m_slots[index3].next = this.m_buckets[index1] - 1;
  905.       this.m_buckets[index1] = index3 + 1;
  906.       ++this.m_count;
  907.       ++this.m_version;
  908.       location = index3;
  909.       return true;
  910.     }
  911.  
  912.     [SecurityCritical]
  913.     private unsafe HashSet<T>.ElementCount CheckUniqueAndUnfoundElements(IEnumerable<T> other, bool returnIfUnfound)
  914.     {
  915.       if (this.m_count == 0)
  916.       {
  917.         int num = 0;
  918.         using (IEnumerator<T> enumerator = other.GetEnumerator())
  919.         {
  920.           if (enumerator.MoveNext())
  921.           {
  922.             T current = enumerator.Current;
  923.             ++num;
  924.           }
  925.         }
  926.         HashSet<T>.ElementCount elementCount;
  927.         elementCount.uniqueCount = 0;
  928.         elementCount.unfoundCount = num;
  929.         return elementCount;
  930.       }
  931.       else
  932.       {
  933.         int length = BitHelper.ToIntArrayLength(this.m_lastIndex);
  934.         BitHelper bitHelper;
  935.         if (length <= 100)
  936.         {
  937.           int* bitArrayPtr = stackalloc int[length];
  938.           bitHelper = new BitHelper(bitArrayPtr, length);
  939.         }
  940.         else
  941.           bitHelper = new BitHelper(new int[length], length);
  942.         int num1 = 0;
  943.         int num2 = 0;
  944.         foreach (T obj in other)
  945.         {
  946.           int bitPosition = this.InternalIndexOf(obj);
  947.           if (bitPosition >= 0)
  948.           {
  949.             if (!bitHelper.IsMarked(bitPosition))
  950.             {
  951.               bitHelper.MarkBit(bitPosition);
  952.               ++num2;
  953.             }
  954.           }
  955.           else
  956.           {
  957.             ++num1;
  958.             if (returnIfUnfound)
  959.               break;
  960.           }
  961.         }
  962.         HashSet<T>.ElementCount elementCount;
  963.         elementCount.uniqueCount = num2;
  964.         elementCount.unfoundCount = num1;
  965.         return elementCount;
  966.       }
  967.     }
  968.  
  969.     internal T[] ToArray()
  970.     {
  971.       T[] array = new T[this.Count];
  972.       this.CopyTo(array);
  973.       return array;
  974.     }
  975.  
  976.     internal static bool HashSetEquals(HashSet<T> set1, HashSet<T> set2, IEqualityComparer<T> comparer)
  977.     {
  978.       if (set1 == null)
  979.         return set2 == null;
  980.       if (set2 == null)
  981.         return false;
  982.       if (HashSet<T>.AreEqualityComparersEqual(set1, set2))
  983.       {
  984.         if (set1.Count != set2.Count)
  985.           return false;
  986.         foreach (T obj in set2)
  987.         {
  988.           if (!set1.Contains(obj))
  989.             return false;
  990.         }
  991.         return true;
  992.       }
  993.       else
  994.       {
  995.         foreach (T x in set2)
  996.         {
  997.           bool flag = false;
  998.           foreach (T y in set1)
  999.           {
  1000.             if (comparer.Equals(x, y))
  1001.             {
  1002.               flag = true;
  1003.               break;
  1004.             }
  1005.           }
  1006.           if (!flag)
  1007.             return false;
  1008.         }
  1009.         return true;
  1010.       }
  1011.     }
  1012.  
  1013.     private static bool AreEqualityComparersEqual(HashSet<T> set1, HashSet<T> set2)
  1014.     {
  1015.       return ((object) set1.Comparer).Equals((object) set2.Comparer);
  1016.     }
  1017.  
  1018.     private int InternalGetHashCode(T item)
  1019.     {
  1020.       if ((object) item == null)
  1021.         return 0;
  1022.       else
  1023.         return this.m_comparer.GetHashCode(item) & int.MaxValue;
  1024.     }
  1025.  
  1026.     internal struct ElementCount
  1027.     {
  1028.       internal int uniqueCount;
  1029.       internal int unfoundCount;
  1030.     }
  1031.  
  1032.     internal struct Slot
  1033.     {
  1034.       internal int hashCode;
  1035.       internal T value;
  1036.       internal int next;
  1037.     }
  1038.  
  1039.     /// <summary>
  1040.     /// Enumerates the elements of a <see cref="T:System.Collections.Generic.HashSet`1"/> object.
  1041.     /// </summary>
  1042.     /// <filterpriority>2</filterpriority>
  1043.     [Serializable]
  1044.     [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
  1045.     public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
  1046.     {
  1047.       private HashSet<T> set;
  1048.       private int index;
  1049.       private int version;
  1050.       private T current;
  1051.  
  1052.       /// <summary>
  1053.       /// Gets the element at the current position of the enumerator.
  1054.       /// </summary>
  1055.       ///
  1056.       /// <returns>
  1057.       /// The element in the <see cref="T:System.Collections.Generic.HashSet`1"/> collection at the current position of the enumerator.
  1058.       /// </returns>
  1059.       public T Current
  1060.       {
  1061.         get
  1062.         {
  1063.           return this.current;
  1064.         }
  1065.       }
  1066.  
  1067.       object IEnumerator.Current
  1068.       {
  1069.         get
  1070.         {
  1071.           if (this.index == 0 || this.index == this.set.m_lastIndex + 1)
  1072.             throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumOpCantHappen"));
  1073.           else
  1074.             return (object) this.Current;
  1075.         }
  1076.       }
  1077.  
  1078.       internal Enumerator(HashSet<T> set)
  1079.       {
  1080.         this.set = set;
  1081.         this.index = 0;
  1082.         this.version = set.m_version;
  1083.         this.current = default (T);
  1084.       }
  1085.  
  1086.       /// <summary>
  1087.       /// Releases all resources used by a <see cref="T:System.Collections.Generic.HashSet`1.Enumerator"/> object.
  1088.       /// </summary>
  1089.       public void Dispose()
  1090.       {
  1091.       }
  1092.  
  1093.       /// <summary>
  1094.       /// Advances the enumerator to the next element of the <see cref="T:System.Collections.Generic.HashSet`1"/> collection.
  1095.       /// </summary>
  1096.       ///
  1097.       /// <returns>
  1098.       /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
  1099.       /// </returns>
  1100.       /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
  1101.       public bool MoveNext()
  1102.       {
  1103.         if (this.version != this.set.m_version)
  1104.           throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion"));
  1105.         for (; this.index < this.set.m_lastIndex; ++this.index)
  1106.         {
  1107.           if (this.set.m_slots[this.index].hashCode >= 0)
  1108.           {
  1109.             this.current = this.set.m_slots[this.index].value;
  1110.             ++this.index;
  1111.             return true;
  1112.           }
  1113.         }
  1114.         this.index = this.set.m_lastIndex + 1;
  1115.         this.current = default (T);
  1116.         return false;
  1117.       }
  1118.  
  1119.       void IEnumerator.Reset()
  1120.       {
  1121.         if (this.version != this.set.m_version)
  1122.           throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion"));
  1123.         this.index = 0;
  1124.         this.current = default (T);
  1125.       }
  1126.     }
  1127.   }
  1128. }
Add Comment
Please, Sign In to add comment