Exemple #1
0
        public void Can_store_and_get_stored_item_count()
        {
            var map = new HashMapLeapfrog <int, string, IntEqualityComparer>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42 + 32 + 32, "3");

            Assert.AreEqual(2, map.Count);
        }
Exemple #2
0
            public void PopulateHashMap_LeapfrogWithDistanceBuffer()
            {
                var keys = _keys;

                for (var i = 0; i < ItemCount; i++)
                {
                    _mapLeapfrogWithDistanceBuffer.AddOrUpdate(keys[i], "a");
                }
                _mapLeapfrogWithDistanceBuffer.AddOrUpdate(_key, _value);
            }
Exemple #3
0
        public void Can_update_a_stored_item_with_new_value()
        {
            var map = new HashMapLeapfrog <int, string, IntEqualityComparer>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42, "3");

            Assert.AreEqual("3", map.GetValueOrDefault(42));
            Assert.AreEqual(1, map.Count);
        }
Exemple #4
0
        public void Can_remove_the_stored_item()
        {
            var map = new HashMapLeapfrog <int, string, IntEqualityComparer>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42 + 32, "2");
            map.AddOrUpdate(42 + 32 + 32, "3");

            map.Remove(42 + 32);

            Assert.AreEqual(2, map.Count);
        }
Exemple #5
0
        public void Can_add_key_with_0_hash_code()
        {
            var map = new HashMapLeapfrog <int, string, IntEqualityComparer>();

            map.AddOrUpdate(0, "aaa");
            map.AddOrUpdate(0 + 32, "2");
            map.AddOrUpdate(0 + 32 + 32, "3");

            string value;

            Assert.IsTrue(map.TryFind(0, out value));

            Assert.AreEqual("aaa", value);
        }
Exemple #6
0
        public void Can_store_and_retrieve_value_from_map()
        {
            var map = new HashMapLeapfrog <int, string, IntEqualityComparer>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42 + 32, "2");

            // interrupt the keys with ne key
            map.AddOrUpdate(43, "a");
            map.AddOrUpdate(43 + 32, "b");

            map.AddOrUpdate(42 + 32 + 32, "3");

            Assert.AreEqual("1", map.GetValueOrDefault(42));
            Assert.AreEqual("2", map.GetValueOrDefault(42 + 32));
            Assert.AreEqual("3", map.GetValueOrDefault(42 + 32 + 32));
            Assert.AreEqual(null, map.GetValueOrDefault(42 + 32 + 32 + 32));

            Assert.AreEqual("a", map.GetValueOrDefault(43));
        }
Exemple #7
0
            public void GlobalSetup()
            {
                var keys = _keys;

                for (var i = 0; i < ItemCount; i++)
                {
                    var key = keys[i];

                    _concurrentDict.TryAdd(key, "a");
                    Interlocked.Exchange(ref _imMap, _imMap.AddOrUpdate(key, "a"));
                    _mapLinearWithDistanceBuffer.AddOrUpdate(key, "a");
                    _mapLeapfrogWithDistanceBuffer.AddOrUpdate(key, "a");
                    _mapLinear.AddOrUpdate(key, "a");
                }

                _concurrentDict.TryAdd(_key, _value);
                Interlocked.Exchange(ref _imMap, _imMap.AddOrUpdate(_key, _value));
                _mapLinearWithDistanceBuffer.AddOrUpdate(_key, _value);
                _mapLeapfrogWithDistanceBuffer.AddOrUpdate(_key, _value);
                _mapLinear.AddOrUpdate(_key, _value);
            }
Exemple #8
0
        public void Can_quickly_find_the_scattered_items_with_the_same_cache()
        {
            var map = new HashMapLeapfrog <int, string, IntEqualityComparer>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(43, "a");
            map.AddOrUpdate(42 + 32, "2");
            map.AddOrUpdate(45, "b");
            map.AddOrUpdate(46, "c");
            map.AddOrUpdate(42 + 32 + 32, "3");

            string value;

            Assert.IsTrue(map.TryFind(42 + 32, out value));
            Assert.AreEqual("2", value);

            Assert.IsTrue(map.TryFind(42 + 32 + 32, out value));
            Assert.AreEqual("3", value);
        }