Skip to content

What about adding a ConcurrentSet<T>? #16443

Closed

Description

@JohanLarsson

The need for it comes up every now and then. To me it would make sense next to ConcurrentDictionary<TKey, TValue>

Activity

  1. ayende commented on Feb 23, 2016

    @ayende
    Contributor

    What does this gives you that ConcurrentDictionary<T, object> (and just not using the value) ?

  2. JohanLarsson commented on Feb 23, 2016

    @JohanLarsson
    Author

    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.

  3. svick commented on Feb 23, 2016

    @svick
    Member

    @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.

  4. JonHanna commented on Feb 23, 2016

    @JonHanna
    Contributor

    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>.

  5. svick commented on Feb 23, 2016

    @svick
    Member

    @JohanLarsson

    Set operations are perhaps tricky to get right with concurrency.

    I think a ConcurrentSet would be useful even without set operations.

  6. JonHanna commented on Feb 23, 2016

    @JonHanna
    Contributor

    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.

  7. hermitdave commented on Feb 23, 2016

    @hermitdave

    Is there's plan to add this? If there is and it's up for grabs, I can look into it

  8. svick commented on Feb 23, 2016

    @svick
    Member

    @hermitdave You might want to have a look at how the API review process works.

  9. hermitdave commented on Feb 23, 2016

    @hermitdave

    Thanks @svick will keep an eye on this one

  10. JohanLarsson commented on Feb 23, 2016

    @JohanLarsson
    Author

    @svick

    I think a ConcurrentSet would be useful even without set operations.

    Agreed, perhaps it should not be called Set? IDK.

  11. Priya91 commented on Sep 30, 2016

    @Priya91
    Contributor

    @hermitdave Do you have a proposal for this ?

  12. hermitdave commented on Sep 30, 2016

    @hermitdave

    @Priya91 oops forgot about this one.. I'll get started asap

  13. hermitdave commented on Oct 3, 2016

    @hermitdave

    Starting work on this

  14. 11 remaining items

  15. LeaFrock commented on Feb 13, 2019

    @LeaFrock
    Contributor

    @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.

  16. reggaeguitar commented on Aug 9, 2019

    @reggaeguitar
  17. JohanLarsson commented on Aug 9, 2019

    @JohanLarsson
    Author

    @reggaeguitar fixed the link.

  18. markusschaber commented on Dec 19, 2019

    @markusschaber

    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.

    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).

  19. transferred this issue fromdotnet/corefxon Jan 31, 2020
  20. added this to the 5.0 milestone on Jan 31, 2020
  21. removed
    untriagedNew issue has not been triaged by the area owner
    on May 6, 2020
  22. modified the milestones: 5.0.0, Future on Jun 24, 2020
  23. MgSam commented on Jul 15, 2020

    @MgSam

    So no one ever made an API proposal for this? Maybe you guys should add the up-for-grabs label.

  24. LeaFrock commented on Jul 25, 2020

    @LeaFrock
    Contributor

    @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.

  25. jkotas commented on Jul 25, 2020

    @jkotas
    Member

    Duplicate of #39919 that has actual API proposal

  26. ghost locked as resolved and limited conversation to collaborators on Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions