You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nothing but communicates intent better imo. I usually do stuff like this (not a proper set).
Set operations are perhaps tricky to get right with concurrency.
Reacted by Andrei Chasovskikh, baterja, maxiptah, Anil Mujagić, cocowalla, Mike Marynowski, Shad Storhaug, Clement Gutel, Sergey Kostrukov, Markus Schaber and 1 more
@ayende Apart from the "it's clearer what this code does" reason and the precedent of having HashSet<T>, there is a small, but measurable, difference in performance and memory consumption.
A very simple test: when I add a million values to Dictionary<int, int>, it takes 42 ms and consumes 26.6 MB of memory, while with HashSet<int>, it takes 38 ms and consumes 21.3 MB.
I assume the difference with concurrent collections would be similar.
If anything more so, since the concurrency consideration means there are a few spots that want to be particularly efficient, so not having to do anything with values would be an even greater gain there than with HashSet<T>.
Set operations are perhaps tricky to get right with concurrency.
I think a ConcurrentSet would be useful even without set operations.
Reacted by Joseph Musser, Kerem Kat, Denis Ivanov, Jofairden, Jeremy Nicoll, Oriol Mesa, Yair Halberstadt, Mykhailo Matviiv, jamesoleary123, Weihan Li and 6 more
@vancem I can't agree more! But three years passed, and no ConcurrentHashSet yet =.=
I think most of us want a kind of collections which is similar to ConcurrentBag, but its elements are never duplicated and its 'Contains()' is an O(1) operation like HashSet.
We can make it using ConcurrentDictionary, but that implementation is too ugly.
Reacted by Nicolas Musset, Paurian, Skyler Berg, Ricardo Oliveira, reggaeguitar, Mike Marynowski, Kogokana, Athos and Bereznikov Alexey
I think most of us want a kind of collections which is similar to ConcurrentBag, but its elements are never duplicated and its 'Contains()' is an O(1) operation like HashSet.
Activity
ayende commentedon Feb 23, 2016
What does this gives you that ConcurrentDictionary<T, object> (and just not using the value) ?
JohanLarsson commentedon Feb 23, 2016
Nothing but communicates intent better imo. I usually do stuff like this (not a proper set).
Set operations are perhaps tricky to get right with concurrency.
svick commentedon Feb 23, 2016
@ayende Apart from the "it's clearer what this code does" reason and the precedent of having
HashSet<T>, there is a small, but measurable, difference in performance and memory consumption.A very simple test: when I add a million values to
Dictionary<int, int>, it takes 42 ms and consumes 26.6 MB of memory, while withHashSet<int>, it takes 38 ms and consumes 21.3 MB.I assume the difference with concurrent collections would be similar.
JonHanna commentedon Feb 23, 2016
If anything more so, since the concurrency consideration means there are a few spots that want to be particularly efficient, so not having to do anything with values would be an even greater gain there than with
HashSet<T>.svick commentedon Feb 23, 2016
@JohanLarsson
I think a
ConcurrentSetwould be useful even without set operations.JonHanna commentedon Feb 23, 2016
I know of one C# concurrent hash set and one in Java and neither offer concurrency on set operations, only on the add, remove, contains.
hermitdave commentedon Feb 23, 2016
Is there's plan to add this? If there is and it's up for grabs, I can look into it
svick commentedon Feb 23, 2016
@hermitdave You might want to have a look at how the API review process works.
hermitdave commentedon Feb 23, 2016
Thanks @svick will keep an eye on this one
JohanLarsson commentedon Feb 23, 2016
@svick
Agreed, perhaps it should not be called
Set? IDK.Priya91 commentedon Sep 30, 2016
@hermitdave Do you have a proposal for this ?
hermitdave commentedon Sep 30, 2016
@Priya91 oops forgot about this one.. I'll get started asap
hermitdave commentedon Oct 3, 2016
Starting work on this
11 remaining items
LeaFrock commentedon Feb 13, 2019
@vancem I can't agree more! But three years passed, and no ConcurrentHashSet yet =.=
I think most of us want a kind of collections which is similar to ConcurrentBag, but its elements are never duplicated and its 'Contains()' is an O(1) operation like HashSet.
We can make it using ConcurrentDictionary, but that implementation is too ugly.
reggaeguitar commentedon Aug 9, 2019
JohanLarsson commentedon Aug 9, 2019
@reggaeguitar fixed the link.
markusschaber commentedon Dec 19, 2019
And which allows to remove a specific element, instead of just a random one (I just needed this today, and see https://stackoverflow.com/questions/3029818/how-to-remove-a-single-specific-object-from-a-concurrentbag for another example).
MgSam commentedon Jul 15, 2020
So no one ever made an API proposal for this? Maybe you guys should add the
up-for-grabslabel.LeaFrock commentedon Jul 25, 2020
@MgSam I can't stand it anymore, so I've spent some time on the API proposal.
Details see #39919 . Let's promote it and finally make it.
jkotas commentedon Jul 25, 2020
Duplicate of #39919 that has actual API proposal