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

            target.DoOrAdd(1, x => "1!", "1");
            Assert.Equal("1", target.GetOrThrow(1));
            target.DoOrAdd(1, x => "1!", "1");
            Assert.Equal("1!", target.GetOrThrow(1));
        }
        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));
        }
        public void AddUpdate(int i)
        {
            var thing = new ConcurrentIndexed <int, string>();

            thing.DoOrAdd(i, (s) => s + " world", "hello");
            Assert.Equal("hello", thing.GetOrThrow(i));
            thing.DoOrAdd(i, (s) => s + " world", "hello");
            Assert.Equal("hello world", thing.GetOrThrow(i));
        }
        public void GetOrTrhow()
        {
            var target = new ConcurrentIndexed <int, string>();

            Assert.ThrowsAny <Exception>(() => target.GetOrThrow(1));

            target.AddOrThrow(1, "1");

            Assert.Equal("1", target.GetOrThrow(1));
        }
        public void AddUpdateOrThrow(int i)
        {
            var thing = new ConcurrentIndexed <int, string>();

            thing.AddOrThrow(i, "hello");
            Assert.Equal("hello", thing.GetOrThrow(i));
            Assert.Throws <Exception>(() =>
            {
                thing.AddOrThrow(i, "hello");
            });

            thing.UpdateOrThrow(i, (s) => s + " world");
            Assert.Equal("hello world", thing.GetOrThrow(i));
        }
        public void UpdateFallback(int i)
        {
            var thing = new ConcurrentIndexed <int, string>();

            Assert.Equal("not hello", thing.DoOrAdd(i, (x) => x + " world", "not hello"));
            Assert.Equal("not hello", thing.GetOrThrow(i));
        }
Exemplo n.º 7
0
        internal void AddField(IOrType <IEntryPointDefinition, IImplementationDefinition, IInternalMethodDefinition> codeElement, IMemberDefinition contextDefinition)
        {
            fields.TryAdd(contextDefinition, new List <IOrType <IEntryPointDefinition, IImplementationDefinition, IInternalMethodDefinition> >());

            var list = fields.GetOrThrow(contextDefinition);

            if (!list.Contains(codeElement))
            {
                list.Add(codeElement);
            }
        }
Exemplo n.º 8
0
 //[Benchmark]
 public void A()
 {
     rawConcurrentHashIndexed.GetOrThrow(1);
 }