Пример #1
0
        private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <Dictionary <string, int>, int> test)
        {
            var pool = DictionaryPool <string, int> .Create(C);

            void testCore(Dictionary <string, int> map)
            {
                var len = map.Count;

                Assert.AreEqual(0, len);

                var L = test(map);

                len = map.Count;
                Assert.AreEqual(L, len);
            }

            if (useRAII)
            {
                Run(() => pool.New(), o => o.Dictionary, o => o.Dispose(), testCore, P, M, noisy);
            }
            else
            {
                Run(() => pool.Allocate(), o => o, o => pool.Free(o), testCore, P, M, noisy);
            }
        }
Пример #2
0
        public void ReplaceGpss(IEnumerable <GridGpsSource> gpsSources)
        {
            var sources = DictionaryPool <long, LocalGpsSource> .Create();

            foreach (var src in gpsSources)
            {
                if (TryCreateGps(src, out var localGpsSource))
                {
                    sources[localGpsSource.Id] = localGpsSource;
                }
            }

            // remove GPSs that don't exist anymore
            foreach (var(existingGpsId, _) in _gpsSources.ToArray())
            {
                if (!sources.ContainsKey(existingGpsId))
                {
                    _gpsSources.Remove(existingGpsId);
                    _gpsApi.RemoveLocalGps(existingGpsId);
                }
            }

            // add/update other GPSs
            foreach (var(id, src) in sources)
            {
                _gpsSources[id] = src;
                _gpsApi.AddOrUpdateLocalGps(src);
            }

            DictionaryPool <long, LocalGpsSource> .Release(sources);
        }
Пример #3
0
        public void PooledDictionary_ArgumentChecking()
        {
            Assert.ThrowsException <ArgumentNullException>(() => DictionaryPool <string, int> .Create(4, comparer: null));

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => DictionaryPool <string, int> .Create(4, -1));

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => DictionaryPool <string, int> .Create(4, -1, EqualityComparer <string> .Default));
            Assert.ThrowsException <ArgumentNullException>(() => DictionaryPool <string, int> .Create(4, 16, comparer: null));

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => DictionaryPool <string, int> .Create(4, 16, EqualityComparer <string> .Default, -1));
        }
Пример #4
0
        public void PooledDictionary_GottenTooBig()
        {
            var bigPool = DictionaryPool <int, string> .Create(1, 16, EqualityComparer <int> .Default, 2048);

            var smallPool = DictionaryPool <int, string> .Create(1, 16, EqualityComparer <int> .Default, 16);

            TooBig(() => PooledDictionary <int, string> .New(), h => h.Dictionary, (h, n) => { for (var i = 0; i < n; i++)
                                                                                               {
                                                                                                   h.Add(i, "");
                                                                                               }
                   }, 1024);
            TooBig(() => bigPool.New(), h => h.Dictionary, (h, n) => { for (var i = 0; i < n; i++)
                                                                       {
                                                                           h.Add(i, "");
                                                                       }
                   }, 2048);
            TooBig(() => smallPool.New(), h => h.Dictionary, (h, n) => { for (var i = 0; i < n; i++)
                                                                         {
                                                                             h.Add(i, "");
                                                                         }
                   }, 16);
        }
Пример #5
0
        public void PooledDictionary_Simple4()
        {
            var pool = DictionaryPool <string, int> .Create(4, 16, EqualityComparer <string> .Default);

            PooledDictionary_Simple_Impl(pool);
        }
Пример #6
0
        public void PooledDictionary_Simple3()
        {
            var pool = DictionaryPool <string, int> .Create(4, 16);

            PooledDictionary_Simple_Impl(pool);
        }