Esempio n. 1
0
        public void stress_test()
        {
            var rnd = new Random();
            // we deliberately use a small initial size to stress the scaling.
            // if you can afford to oversize the map, that will make things a lot faster
            var mem     = new MemorySimulator(Mega.Bytes(10));
            var subject = new TaggedHashMap(100, new Allocator(0, Mega.Bytes(10), mem), mem);

            subject.Add(0, 1);
            for (int i = 0; i < /*100000*/ 25_000; i++) // 25'000 should be under a second
            {
                if (!subject.Put((ulong)rnd.Next(1, 1_000_000), (ulong)i, true))
                {
                    Assert.Fail("Put rejected the change");
                }
                subject.Remove((ulong)rnd.Next(1, 1_000_000));
            }

            Assert.That(subject.Count, Is.GreaterThan(1000)); // there will probably be key collisions

            var ok = subject.Get(0, out var val);

            Assert.That(ok, Is.True);
            Assert.That(val, Is.EqualTo(1));
        }
Esempio n. 2
0
        public void can_store_and_retrieve_items()
        {
            var mem     = new MemorySimulator(Mega.Bytes(1));
            var subject = new TaggedHashMap(64, new Allocator(0, Mega.Bytes(1), mem), mem);

            subject.Add(50000000, 123);
            subject.Add(1, 456);

            var ok1 = subject.Get(1, out var val1);
            var ok2 = subject.Get(50000000, out var val2);
            var ok3 = subject.Get(50, out _);

            Assert.That(ok1, Is.True);
            Assert.That(ok2, Is.True);
            Assert.That(ok3, Is.False);

            Assert.That(val1, Is.EqualTo(456));
            Assert.That(val2, Is.EqualTo(123));
        }
Esempio n. 3
0
        public void put_can_replace_an_existing_value()
        {
            var mem     = new MemorySimulator(Mega.Bytes(1));
            var subject = new TaggedHashMap(64, new Allocator(0, Mega.Bytes(1), mem), mem);

            subject.Put(1, 1, true);
            subject.Put(1, 2, true);  // overwrite
            subject.Put(1, 3, false); // silently abort

            subject.Get(1, out var result);
            Assert.That(result, Is.EqualTo(2));
        }
Esempio n. 4
0
        public void can_remove_values()
        {
            var mem     = new MemorySimulator(Mega.Bytes(1));
            var subject = new TaggedHashMap(64, new Allocator(0, Mega.Bytes(1), mem), mem);

            subject.Add(50000000, 123);
            subject.Add(1, 456);

            var ok1 = subject.Get(1, out _);
            var ok2 = subject.Get(50000000, out _);
            var ok3 = subject.Get(50, out _);

            Assert.That(ok1, Is.True);
            Assert.That(ok2, Is.True);
            Assert.That(ok3, Is.False);

            // remove one value at beginning
            subject.Remove(1);

            ok1 = subject.Get(1, out _);
            ok2 = subject.Get(50000000, out _);
            ok3 = subject.Get(50, out _);

            Assert.That(ok1, Is.False);
            Assert.That(ok2, Is.True);
            Assert.That(ok3, Is.False);
        }