Esempio n. 1
0
        public bool TryUpdate(TKey key, TValue value, TValue comparisonValue)
        {
            var oldValObj = DictionaryImpl.ToObjectValue(comparisonValue);
            var newValObj = DictionaryImpl.ToObjectValue(value);

            return(_table.PutIfMatch(key, newValObj, ref oldValObj, DictionaryImpl.ValueMatch.OldValue));
        }
Esempio n. 2
0
        public bool TryAdd(TKey key, TValue value)
        {
            object oldValObj = null;
            var    newValObj = DictionaryImpl.ToObjectValue(value);

            return(_table.PutIfMatch(key, newValObj, ref oldValObj, DictionaryImpl.ValueMatch.NullOrDead));
        }
Esempio n. 3
0
        public bool Remove(KeyValuePair <TKey, TValue> item)
        {
            var oldValObj = DictionaryImpl.ToObjectValue(item.Value);

            return(_table.PutIfMatch(item.Key, DictionaryImpl.TOMBSTONE, ref oldValObj,
                                     DictionaryImpl.ValueMatch.OldValue));
        }
Esempio n. 4
0
        public TValue GetOrAdd(TKey key, TValue value)
        {
            object oldValObj = null;
            var    newValObj = DictionaryImpl.ToObjectValue(value);

            if (_table.PutIfMatch(key, newValObj, ref oldValObj, DictionaryImpl.ValueMatch.NullOrDead))
            {
                return(value);
            }

            // PERF: this would be nice to have as a helper,
            // but it does not get inlined
            if (default(TValue) == null && oldValObj == DictionaryImpl.NULLVALUE)
            {
                oldValObj = null;
            }

            return((TValue)oldValObj);
        }
Esempio n. 5
0
        public TValue this[TKey key]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                var oldValObj = _table.TryGetValue(key);

                Debug.Assert(!(oldValObj is DictionaryImpl.Prime));

                if (oldValObj != null)
                {
                    // PERF: this would be nice to have as a helper,
                    // but it does not get inlined
                    TValue value;
                    if (default(TValue) == null && oldValObj == DictionaryImpl.NULLVALUE)
                    {
                        value = default(TValue);
                    }
                    else
                    {
                        value = (TValue)oldValObj;
                    }

                    return(value);
                }

                return(ThrowKeyNotFound());
            }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            set
            {
                object oldValObj = null;
                var    newValObj = DictionaryImpl.ToObjectValue(value);
                _table.PutIfMatch(key, newValObj, ref oldValObj, DictionaryImpl.ValueMatch.Any);
            }
        }