Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/System.Collections/src/System/Collections/Generic/HashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public HashSet(IEqualityComparer<T> comparer)
_version = 0;
}

public HashSet(int capacity)
: this(capacity, EqualityComparer<T>.Default)
{ }

public HashSet(IEnumerable<T> collection)
: this(collection, EqualityComparer<T>.Default)
{ }
Expand Down Expand Up @@ -131,6 +135,21 @@ public HashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
}
}

public HashSet(int capacity, IEqualityComparer<T> comparer)
: this(comparer)
{
if (capacity < 0)
{
throw new ArgumentOutOfRangeException("capacity");
}
Contract.EndContractBlock();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder (not tied to this commit) if we should strip Contract.EndContractBlock et al since we're not using the code contract tooling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is something definitely worth considering, to this point I've not seen the value of ripping it all out yet. It may still be somewhat useful if we do get the C# vNext contracts feature in providing some hints about the contracts.


if (capacity > 0)
{
Initialize(capacity);
}
}

#endregion

#region ICollection<T> methods
Expand Down