public LinkedDictionary(int capacity, IEqualityComparer <TKey> comparer, bool accessRecord, ILinkedDictionaryCache <TKey, TValue> cacheHandler) { if (capacity < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ThrowHelper.capacity); } if (capacity > 0) { Initialize(capacity); } if (comparer == null) { comparer = EqualityComparer <TKey> .Default; } this.comparer = comparer; this.accessRecord = accessRecord; this.cacheHandler = cacheHandler; headEntry = new Entry() { nextEntry = -1, prevEntry = -1, }; }
public LinkedDictionary(IDictionary <TKey, TValue> dictionary, IEqualityComparer <TKey> comparer, bool accessRecord, ILinkedDictionaryCache <TKey, TValue> cacheHandler) : this(dictionary != null ? dictionary.Count : 0, comparer, accessRecord, cacheHandler) { if (dictionary == null) { ThrowHelper.ThrowArgumentNullException(ThrowHelper.dictionary); } foreach (var keyValuePair in dictionary) { Add(keyValuePair.Key, keyValuePair.Value); } }
/// <summary> /// removeEldestEntry是用于自定义是否删除最旧的数据,可用于缓存的设计 /// entryRemoved只有在removeEldestEntry有定义并且有返回true的时候才调用 /// </summary> /// <param name="removeEldestEntry"></param> /// <param name="entryRemoved"></param> public LinkedDictionary(ILinkedDictionaryCache <TKey, TValue> cacheHandler) : this(0, null, false, cacheHandler) { }