{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/382","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/382/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/382/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/382/events","html_url":"https://github.com/dotnet/corefx/issues/382","id":53862477,"number":382,"title":"Add ctor to HashSet<T> that allows the initial capacity to be specified","user":{"login":"mattwarren","id":157298,"avatar_url":"https://avatars.githubusercontent.com/u/157298?v=3","gravatar_id":"","url":"https://api.github.com/users/mattwarren","html_url":"https://github.com/mattwarren","followers_url":"https://api.github.com/users/mattwarren/followers","following_url":"https://api.github.com/users/mattwarren/following{/other_user}","gists_url":"https://api.github.com/users/mattwarren/gists{/gist_id}","starred_url":"https://api.github.com/users/mattwarren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattwarren/subscriptions","organizations_url":"https://api.github.com/users/mattwarren/orgs","repos_url":"https://api.github.com/users/mattwarren/repos","events_url":"https://api.github.com/users/mattwarren/events{/privacy}","received_events_url":"https://api.github.com/users/mattwarren/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/corefx/labels/accepting%20prs","name":"accepting prs","color":"159818"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/api%20addition","name":"api addition","color":"207de5"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/System.Collections.Generic","name":"System.Collections.Generic","color":"d4c5f9"}],"state":"open","locked":false,"assignee":{"login":"ellismg","id":9602953,"avatar_url":"https://avatars.githubusercontent.com/u/9602953?v=3","gravatar_id":"","url":"https://api.github.com/users/ellismg","html_url":"https://github.com/ellismg","followers_url":"https://api.github.com/users/ellismg/followers","following_url":"https://api.github.com/users/ellismg/following{/other_user}","gists_url":"https://api.github.com/users/ellismg/gists{/gist_id}","starred_url":"https://api.github.com/users/ellismg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellismg/subscriptions","organizations_url":"https://api.github.com/users/ellismg/orgs","repos_url":"https://api.github.com/users/ellismg/repos","events_url":"https://api.github.com/users/ellismg/events{/privacy}","received_events_url":"https://api.github.com/users/ellismg/received_events","type":"User","site_admin":false},"milestone":null,"comments":9,"created_at":"2015-01-09T12:20:08Z","updated_at":"2015-01-24T13:49:07Z","closed_at":null,"body":"Unlike most other collections within the `System.Collections` namespace, `HashSet<T>` doesn't have a [constructor overload](http://msdn.microsoft.com/en-us/library/bb354549(v=vs.110).aspx) that allows you to pass in the expected capacity. It will only let you pass in an [`IEnumerable<T> collection`](http://referencesource.microsoft.com/#System.Core/System/Collections/Generic/HashSet.cs,116) of items to pre-populate it with.\r\n\r\nHaving this would enable the use case where you know how many items will be added to the `HashSet<T>` (or at least an upper bound), but don't have them all up front, i.e. they are to be added over time. \r\n\r\nIt would therefore let pre-size the `HashSet<T>` so that it doesn't have to grow over time, with all the associated copying that is needed. This pattern is exposed by other collections, for instance [`List<T>`](http://msdn.microsoft.com/en-us/library/dw8e0z9z(v=vs.110).aspx), to cover this scenario.\r\n\r\nThere's already a private [`Initialize` method](http://referencesource.microsoft.com/#System.Core/System/Collections/Generic/HashSet.cs,831ca3e6d9c0d78b) that will do the work, so unless I'm missing something, it's just a case of calling this.\r\n\r\nIs this something that is worth adding?"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/71317411","html_url":"https://github.com/dotnet/corefx/issues/382#issuecomment-71317411","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/382","id":71317411,"user":{"login":"thomaslevesque","id":1864281,"avatar_url":"https://avatars.githubusercontent.com/u/1864281?v=3","gravatar_id":"","url":"https://api.github.com/users/thomaslevesque","html_url":"https://github.com/thomaslevesque","followers_url":"https://api.github.com/users/thomaslevesque/followers","following_url":"https://api.github.com/users/thomaslevesque/following{/other_user}","gists_url":"https://api.github.com/users/thomaslevesque/gists{/gist_id}","starred_url":"https://api.github.com/users/thomaslevesque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomaslevesque/subscriptions","organizations_url":"https://api.github.com/users/thomaslevesque/orgs","repos_url":"https://api.github.com/users/thomaslevesque/repos","events_url":"https://api.github.com/users/thomaslevesque/events{/privacy}","received_events_url":"https://api.github.com/users/thomaslevesque/received_events","type":"User","site_admin":false},"created_at":"2015-01-24T13:49:07Z","updated_at":"2015-01-24T13:49:07Z","body":"Since we're talking about the `HashSet<T>` constructor, see this related issue: #498 \r\n"}}