How might a class like .NET's ConcurrentBag be implemented?

后端 未结 5 797
夕颜
夕颜 2021-02-07 21:49

I find myself very intrigued by the existence of a ConcurrentBag class in the upcoming .NET 4.0 framework:

Bags are useful for storing objects wh

5条回答
  •  孤街浪徒
    2021-02-07 22:50

    I believe the concept of a 'Bag' is synonymous with 'Multiset'.

    There are a number of "Bag"/"Multiset" implementations (these happen to be java) that are open source if you are interested in how they are implemented.

    These implementations show that a 'Bag' can be implemented in any number of ways depending on your needs. There are examples of TreeMultiset, HashMultiset, LinkedHashMultiset, ConcurrentHashMultiset.

    Google Collections
    Google has a number of "MultiSet" implementations, one being a ConcurrentHashMultiset.

    Apache Commons
    Apache has a number of "Bag" implementations.

提交回复
热议问题