using System; using System.Collections.Generic; namespace fastJSON { internal class SafeDictionary<TKey, TValue> { private readonly object _Padlock = new object(); private readonly Dictionary<TKey, TValue> _Dictionary = new Dictionary<TKey, TValue>(); public bool TryGetValue(TKey key, out TValue value) { return _Dictionary.TryGetValue(key, out value); } public TValue this[TKey key] { get { return _Dictionary[key]; } } public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() { return ((ICollection<KeyValuePair<TKey, TValue>>)_Dictionary).GetEnumerator(); } public void Add(TKey key, TValue value) { lock (_Padlock) { if (_Dictionary.ContainsKey(key) == false) _Dictionary.Add(key, value); } } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Math Primers for Programmers