Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the dictionary with the specified
        /// initial capacity, the specified eviction, and uses the
        /// provide equality comparer for the key type.
        /// </summary>
        /// <param name="capacity">
        /// The initial number of elements that the dictionary can contain before resizing internally.
        /// </param>
        /// <param name="evictionMode">
        /// Specifies whether the most recent or least recent entry is evicted when
        /// <see cref="SetAndMaintainCount(TKey, TValue)"/> is called.
        /// </param>
        /// <param name="comparer">
        /// The <see cref="IEqualityComparer{T}"/> implementation to use when comparing keys,
        /// or null to use the default comparer for the type of the key.
        /// </param>
        public RecentDictionary(int capacity, RecentDictionaryEvictionMode evictionMode, IEqualityComparer <TKey> comparer)
        {
            if (capacity < 0 || capacity > (1 << 30))
            {
                throw new ArgumentOutOfRangeException(nameof(capacity), capacity, "Capacity must be between 0 and 1,073,741,824 (inclusive)");
            }

            _comparer  = comparer ?? EqualityComparer <TKey> .Default;
            _evictMode = evictionMode;

            int initialBucketCount;

            if (capacity <= 4)
            {
                initialBucketCount = 8;
            }
            else
            {
                initialBucketCount = NextPowerOfTwo(capacity);
            }
            _buckets    = new Node[initialBucketCount];
            _bucketMask = initialBucketCount - 1;
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the dictionary that is empty,
 /// uses the specified eviction mode,
 /// has the default initial capacity,
 /// and uses the default equality comparer for the key type.
 /// </summary>
 /// <param name="evictionMode">
 /// Specifies whether the most recent or least recent entry is evicted when
 /// <see cref="SetAndMaintainCount(TKey, TValue)"/> is called.
 /// </param>
 public RecentDictionary(RecentDictionaryEvictionMode evictionMode) : this(0, evictionMode, null)
 {
 }