Beispiel #1
0
            public void Initialize()
            {
                _prng     = new Random(Seed);
                _lookups  = new int[NumLookups];
                _inputsGt = new HashSet <int>(NumEntries);

                _inputsTestSimd = new VectorFlatHashSet <int>();
                _inputsTestSimd.Reserve((uint)NumEntries);

                for (int i = 0; i < _lookups.Length; ++i)
                {
                    if ((i & 1) == 0 || _inputsGt.Count == NumEntries)
                    {
                        _lookups[i] = ~_prng.Next();
                    }
                    else
                    {
                        var num = NextExcept(_inputsGt, _prng);
                        _lookups[i] = num;
                        _inputsGt.Add(num);
                        _inputsTestSimd.Add(num);
                    }
                }

                var len = NumEntries;

                while (_inputsGt.Count < len)
                {
                    var num = NextExcept(_inputsGt, _prng);
                    _inputsGt.Add(num);
                    _inputsTestSimd.Add(num);
                }
            }
Beispiel #2
0
        private void InsertLookup(int seed)
        {
            var set = new VectorFlatHashSet <int>();
            //set.Reserve(10000);
            var gt           = new HashSet <int>(10000);
            var notContained = //Vector<int>.Reserve(10000);
                               new List <int>(10000);

            var prng = new Random(seed);

            for (int i = 0; i < 10000; ++i)
            {
                int num = NextExcept(prng, gt);
                if ((i & 1) == 0)
                {
                    gt.Add(num);
                    set.Add(num);
                }
                else
                {
                    notContained.Add(num);
                }
            }

            foreach (int x in gt)
            {
                Assert.Contains(x, set);
            }

            foreach (int x in notContained)
            {
                Assert.DoesNotContain(x, set);
            }
        }
Beispiel #3
0
        public ISet <int> VFHSAdd(int seed, int numElements)
        {
            var set = new VectorFlatHashSet <int>();
            var rnd = new Random(seed);

            for (int i = 0; i < numElements; ++i)
            {
                set.Add(rnd.Next(numElements * 2));
            }
            return(set);
        }
Beispiel #4
0
        public ISet <string> RVFHSAddStr(int seed, uint numElements)
        {
            var set = new VectorFlatHashSet <string>(numElements);
            var rnd = new Random(seed);

            for (int i = 0; i < numElements; ++i)
            {
                set.Add(RandomString(BitOperations.Log2(numElements), rnd));
            }
            return(set);
        }
Beispiel #5
0
            public void Initialize()
            {
                var prng = new Random(Seed);

                gt  = new HashSet <int>(NumEntries);
                set = new VectorFlatHashSet <int>((uint)NumEntries);

                for (uint i = 0; i < NumEntries; ++i)
                {
                    var x = NextExcept(gt, prng);
                    gt.Add(x);
                    set.Add(x);
                }
            }
Beispiel #6
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);
        }