Я пытаюсь реализовать ConcurrentHashSet в духе ConcurrentDictionary, подход заключается в том, чтобы использовать внутреннюю поддержку ConcurrentDictionary и писать небольшие методы делегирования, это то, как далеко я получил, но хорошо, что теоретические методы набора я застрял, особенно. Я не уверен, могу ли я использовать foreach и не нарушать concurrency
public class ConcurrentHashSet<TElement> : ISet<TElement>
{
    private readonly ConcurrentDictionary<TElement, object> _internal;
    public ConcurrentHashSet(IEnumerable<TElement> elements = null)
    {
        _internal = new ConcurrentDictionary<TElement, object>();
        if (elements != null)
            UnionWith(elements);
    }
    public void UnionWith(IEnumerable<TElement> other)
    {
        if (other == null) throw new ArgumentNullException("other");
        foreach (var otherElement in other)
            Add(otherElement);
    }
    public void IntersectWith(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public void ExceptWith(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public void SymmetricExceptWith(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public bool IsSubsetOf(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public bool IsSupersetOf(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public bool IsProperSupersetOf(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public bool IsProperSubsetOf(IEnumerable<TElement> other)
    {
        throw new NotImplementedException();
    }
    public bool Overlaps(IEnumerable<TElement> other)
    {
        return other.Any(otherElement => _internal.ContainsKey(otherElement));
    }
    public bool SetEquals(IEnumerable<TElement> other)
    {
        int otherCount = 0;
        int thisCount = Count;
        foreach (var otherElement in other)
        {
            otherCount++;
            if (!_internal.ContainsKey(otherElement))
                return false;
        }
        return otherCount == thisCount;
    }
    public bool Add(TElement item)
    {
        return _internal.TryAdd(item, null);
    }
    public void Clear()
    {
        _internal.Clear();
    }
    // I am not sure here if that fullfills contract correctly
    void ICollection<TElement>.Add(TElement item)
    {
        Add(item);
    }
    public bool Contains(TElement item)
    {
        return _internal.ContainsKey(item);
    }
    public void CopyTo(TElement[] array, int arrayIndex)
    {
        _internal.Keys.CopyTo(array, arrayIndex);
    }
    public bool Remove(TElement item)
    {
        object ignore;
        return _internal.TryRemove(item, out ignore);
    }
    public int Count
    {
        get { return _internal.Count; }
    }
    public bool IsReadOnly
    {
        get { return false; }
    }
    public IEnumerator<TElement> GetEnumerator()
    {
        return _internal.Keys.GetEnumerator();
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}
