public void Set()
        {
            var target = new ConcurrentIndexed <int, string>();

            target.Set(1, "1");
            Assert.Equal("1", target.GetOrThrow(1));
            target.Set(1, "1!");
            Assert.Equal("1!", target.GetOrThrow(1));
        }
예제 #2
0
        public void Setup()
        {
            random = new Random((int)DateTime.Now.Ticks);
            mine   = new ConcurrentIndexed <int, string>();
            concurrentDictionary = new ConcurrentDictionary <int, string>();

            void cdRead()
            {
                for (var i = 0; i < Reps; i++)
                {
                    concurrentDictionary[random.Next(1, RandomRange + 1)] = "";
                }
            }

            cdActions = new List <Action>();
            for (int i = 0; i < Threads; i++)
            {
                cdActions.Add(cdRead);
            }

            void myRead()
            {
                for (var i = 0; i < Reps; i++)
                {
                    mine.Set(random.Next(1, RandomRange + 1), "");
                }
            }

            myActions = new List <Action>();
            for (int i = 0; i < Threads; i++)
            {
                myActions.Add(myRead);
            }
        }
        public void UpdateOrThrow()
        {
            var target = new ConcurrentIndexed <int, string>();

            Assert.ThrowsAny <Exception>(() => target.UpdateOrThrow(1, x => x + "!"));
            target.Set(1, "1");
            Assert.Equal("1!", target.UpdateOrThrow(1, x => x + "!"));
        }
예제 #4
0
        public void Setup()
        {
            concurrentHashIndexedTree2 = new ConcurrentIndexed <HashTest, int>();
            for (var i = 1; i <= Items; i++)
            {
                concurrentHashIndexedTree2.GetOrAdd(new HashTest(1, i), i);
            }

            concurrentDictionary2 = new ConcurrentDictionary <HashTest, int>();
            for (var i = 1; i <= Items; i++)
            {
                concurrentDictionary2.GetOrAdd(new HashTest(1, i), i);
            }

            rawConcurrentHashIndexed = new ConcurrentIndexed <int, int>();
            rawConcurrentHashIndexed.GetOrAdd(1, 1);

            dict = new Dictionary <int, int>
            {
                [1] = 1
            };

            concurrentHashIndexedTree = new ConcurrentIndexed <int, int>();
            concurrentHashIndexedTree.Set(1, 1);
            //concurrentHashIndexedTree.GetOrAdd(new IndexedListNode<int, Concurrent<int>>(1, new Concurrent<int>(1)));
            //concurrentHashIndexedTree.GetOrAdd(new IndexedListNode<int, int>(1,1));
            concurrentDictionary = new ConcurrentDictionary <int, int>
            {
                [1] = 1
            };
            //var r = new Random((int)DateTime.Now.Ticks);
            //data = new Tuple<int, int>[Threads][];
            //for (int i = 0; i < Threads; i++)
            //{
            //    data[i] = new Tuple<int, int>[Items];
            //    for (int j = 0; j < Items; j++)
            //    {
            //        data[i][j] = new Tuple<int, int>(r.Next(1, 1000), r.Next(1, 1000));
            //    }
            //}
        }