What is the lookup time complexity of HashSet(IEqualityComparer)?

A HashSet works via hashing (via IEqualityComparer.GetHashCode) the objects you insert and tosses the objects into buckets per the hash. The buckets themselves are stored in an array, hence the O(1) part. For example (this is not necessarily exactly how the C# implementation works, it just gives a flavor) it takes the first character of … Read more

How can I insert all values of one HashSet into another HashSet?

You don’t want union — as you said, it will create a new HashSet. Instead you can use Extend::extend: use std::collections::HashSet; fn main() { let mut a: HashSet<u16> = [1, 2, 3].iter().copied().collect(); let b: HashSet<u16> = [1, 3, 7, 8, 9].iter().copied().collect(); a.extend(&b); println!(“{:?}”, a); // {8, 3, 2, 1, 7, 9} } (Playground) Extend::extend is … Read more

These Sets allow null. Why can’t I add null elements?

This is why I don’t like to rely on auto-boxing. Java Collections cannot store primitives (for that you will need a third party API like Trove). So, really, when you execute code like this: hashSet.add(2); hashSet.add(5); What is really happening is: hashSet.add(new Integer(2)); hashSet.add(new Integer(5)); Adding a null to the hash set is not the … Read more

Why can’t I retrieve an item from a HashSet without enumeration?

In .Net, what you are probably looking for is KeyedCollection http://msdn.microsoft.com/en-us/library/ms132438.aspx You can get around the nastiness of re-implementing this abstract class each time with some “generic” cleverness. (See IKeyedObject`1.) Note: Any data transfer object which implements IKeyedObject`1 should have an overridden GetHashCode method simply returning this.Key.GetHashCode(); and same goes for equals… My Base Class … Read more

How to implement ConcurrentHashSet in .Net

I just ran into a similar scenario (“I am interested in a fast Add and Contains and Remove”) and implemented this sucker: using System.Collections.Generic; using System.Threading; namespace BlahBlah.Utilities { public class ConcurrentHashSet<T> : IDisposable { private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); private readonly HashSet<T> _hashSet = new HashSet<T>(); #region Implementation of ICollection<T> …ish public … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)