From 38899ee55e5b8a558ee91349ab2042d26ff7a961 Mon Sep 17 00:00:00 2001 From: MarkusSintonen Date: Tue, 30 Jun 2015 21:42:29 +0300 Subject: [PATCH] Add HashSet ctors with capacity Adds ctors to HashSet that accept a capacity. New tests are not included due to System.Collections.dll being a partial facade, and the repo not currently having the infrastructure to enable adding tests for new surface area in partial facades. --- .../src/System/Collections/Generic/HashSet.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/System.Collections/src/System/Collections/Generic/HashSet.cs b/src/System.Collections/src/System/Collections/Generic/HashSet.cs index e08c358589b9..17c83890fffc 100644 --- a/src/System.Collections/src/System/Collections/Generic/HashSet.cs +++ b/src/System.Collections/src/System/Collections/Generic/HashSet.cs @@ -92,6 +92,10 @@ public HashSet(IEqualityComparer comparer) _version = 0; } + public HashSet(int capacity) + : this(capacity, EqualityComparer.Default) + { } + public HashSet(IEnumerable collection) : this(collection, EqualityComparer.Default) { } @@ -131,6 +135,21 @@ public HashSet(IEnumerable collection, IEqualityComparer comparer) } } + public HashSet(int capacity, IEqualityComparer comparer) + : this(comparer) + { + if (capacity < 0) + { + throw new ArgumentOutOfRangeException("capacity"); + } + Contract.EndContractBlock(); + + if (capacity > 0) + { + Initialize(capacity); + } + } + #endregion #region ICollection methods