Today, I need to use an instance of synced version of HashSet in C#, aka, ConcurrentHashSet<T> in tech language.
First, I dig some in GitHub and NuGet. I found 2 solutions contains this solution, as they described. One has the exact name of ConcurrentHashSet, but it’s not implemented the ISet<T>. Another is a big set which contains this class with the name, which is written using ConcurrentDictionary<T>, with no ISet<T> implemented either.
Hmm, it seem that if I really need ISet<T> support, I have to do it myself. Let me create class inherited HashSet<T> to write some overridden methods and properties with lock… Wait a minute, only 3 methods from Object is allowed for overriding? Wtf.
If I cannot stand on the shoulders of HashSet<T>, let me dig the HashSet<T> first. Luckily, Microsoft released the source code of the entire dotNet framework. HashSet<T> is included as well. All I need to copy the whole code into mine and… Uhh? What’s the license of the file?
By asking a lawyer friend, I’m told that I MAY have right to use this code in my program but I’m NOT GRANTED to publish the ConcurrentHashSet<T> I wrote separately. That maybe the reason why I failed in the first step — Microsoft didn’t finish their job and don’t allow anyone to fix it for them.