[TestFixture] class HashSetExample { [Test] public void eg() { var comparer = new OddEvenBag(); var hs = new HashSet<int>(comparer); hs.Add(1); Assert.IsTrue(hs.Contains(3)); Assert.IsFalse(hs.Contains(0));
Besides checking if hs contains an odd number, I want to know which odd number contains. Obviously, I need a method that scales reasonably and doesn't just iterate and search the entire collection.
Another way to rephrase the question: I want to replace the line below THIS LINE HERE with something effective (say, O (1), not O (n)).
For what purpose? I try to put laaaaaa a large number of immutable reference objects similar in size to Point3D. It seems like using a HashSet<Foo> instead of Dictionary<Foo,Foo> saves about 10% in memory. No, obviously, this is not a change of game, but I decided that it would not hurt to try for a quick victory. I apologize if this offended anyone.
Edit: Link to a similar / identical post provided by Balazs Tihany in the comments, posted here for emphasis.
collections c #
fostandy
source share