i3arnon/ConcurrentHashSet

AddRange method

Closed this issue · 1 comments

Would it be possible to add an AddRange method to this very useful library? I'm adding batches of around 100 integers to the list per thread, so I would estimate, that a AddRange method would be beneficial.

Some would expect such a method to be atomic.
That would mean holding a lock throughout the operation which may lead to poor performance.
I prefer to not add this kind of methods to the existing API, as this should be easily achieved with an extension method:

public static class ConcurrentHashSetExtensions
{
    public static void AddRange<T>(this ConcurrentHashSet<T> set, IEnumerable<T> collection)
    {
        foreach (var item in collection)
        {
            set.Add(item);
        }
    }
}