Exemple #1
0
            public int VFHSForEach()
            {
                int ret = 42;

                set.ForEach(x => ret ^= x);

                return(ret);
            }
Exemple #2
0
        private void ForEachTest(int seed)
        {
            var prng = new Random(seed);

            const uint NUM_ENTRIES = 2343;
            const uint len         = 10;

            var gt  = new HashSet <string>((int)NUM_ENTRIES);
            var set = new VectorFlatHashSet <string>(NUM_ENTRIES);

            for (uint i = 0; i < NUM_ENTRIES; ++i)
            {
                string str = RandomString((int)len, prng);

                set.Add(str);
                gt.Add(str);

                Assert.Contains(str, set);

                if ((i & 1) != 0)
                {
                    string rem = RandomString((int)len, prng);

                    bool remSet = set.Remove(rem);
                    bool remGt  = gt.Remove(rem);

                    Assert.Equal(remGt, remSet);
                    Assert.DoesNotContain(rem, set);

                    if (remGt)
                    {
                        str = RandomString((int)len, prng);

                        set.Add(str);
                        gt.Add(str);

                        Assert.Contains(str, set);
                    }
                }
            }

            Assert.Equal(gt.Count, set.Count);

            var fe = new HashSet <string>((int)NUM_ENTRIES);

            foreach (string x in set)
            {
                Assert.True(fe.Add(x));
                Assert.Contains(x, gt);
            }

            Assert.Equal(gt.Count, fe.Count);

            fe.Clear();

            set.ForEach(x => {
                Assert.True(fe.Add(x));
                Assert.Contains(x, gt);
            });

            Assert.Equal(gt.Count, fe.Count);
        }