コード例 #1
0
 public HashSet(IEnumerable <T> collection, IEqualityComparer <T> comparer)
     : this(comparer) {
     if (collection == null)
     {
         throw new ArgumentNullException("collection");
     }
     int             capacity = 0;
     ICollection <T> is2      = collection as ICollection <T>;
     if (is2 != null)
     {
         capacity = is2.Count;
     }
     this.Initialize(capacity);
     this.UnionWith(collection);
     if (((this.m_count == 0) && (this.m_slots.Length > HashHelpers.GetMinPrime())) || ((this.m_count > 0) && ((this.m_slots.Length / this.m_count) > 3)))
     {
         this.TrimExcess();
     }
 }
コード例 #2
0
 public HashSet(IEnumerable <T> collection, IEqualityComparer <T> comparer)
     : this(comparer)
 {
     if (collection == null)
     {
         throw new ArgumentNullException("collection");
     }
     int suggestedCapacity = 0;
     if (collection is ICollection <T> coll)
     {
         suggestedCapacity = coll.Count;
     }
     Initialize(suggestedCapacity);
     this.UnionWith(collection);
     if ((_count == 0 && _slots.Length > HashHelpers.GetMinPrime()) ||
         (_count > 0 && _slots.Length / _count > ShrinkThreshold))
     {
         TrimExcess();
     }
 }