/// <summary>
            /// Initializes a new instance of the <see cref="Enumerator"/> class.
            /// </summary>
            /// <param name="cache">The cache that this enumerator is associated with.</param>
            public Enumerator(NWaySetAssociativeCache <TKey, TValue> cache)
            {
                _cache = cache;

                foreach (var set in cache.Sets)
                {
                    set.Lock.EnterReadLock();
                }
            }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntrySet{TKey, TValue}"/> struct.
        /// </summary>
        /// <param name="cache">The cache that this set belongs to.</param>
        /// <param name="entriesBegin">The beginning index of the range of entry's indexes managed by this instance.</param>
        /// <param name="entriesEnd">The end index of the range of entry's indexes managed by this instance.</param>
        /// <exception cref="ArgumentException">
        /// The indexes of the entries cannot be negative.
        /// or
        /// The index of the entry where this set begins cannot be greater or equal to the index where they end. - entriesBegin
        /// </exception>
        /// <exception cref="ArgumentNullException">cache</exception>
        internal EntrySet(
            NWaySetAssociativeCache <TKey, TValue> cache,
            int entriesBegin,
            int entriesEnd)
        {
            if (entriesBegin < 0 || entriesEnd < 0)
            {
                throw new ArgumentException("The indexes of the entries cannot be negative.");
            }
            if (entriesBegin >= entriesEnd)
            {
                throw new ArgumentException("The index of the entry where this set begins cannot be greater than the index where they end.", nameof(entriesBegin));
            }

            _cache        = cache ?? throw new ArgumentNullException(nameof(cache));
            _entriesBegin = entriesBegin;
            _entriesEnd   = entriesEnd;
            _nextUsage    = 0;
            Lock          = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        }