예제 #1
0
        /// <summary>
        /// Returns the next item to be taken from the back without removing it.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">No more items to be taken.</exception>
        public T Peek()
        {
            T   item;
            int index = Interlocked.Add(ref _indexEnqueue, 0);

            if (index < _capacity && index > 0 && _bucket.TryGet(index, out item))
            {
                return(item);
            }
            else
            {
                throw new System.InvalidOperationException("Empty");
            }
        }
예제 #2
0
        /// <summary>
        /// Determines whether the specified item is contained.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="offset">The offset from the default index.</param>
        /// <returns>The index where the item is set; -1 otherwise.</returns>
        public int Contains(T item, int offset)
        {
            int index = Index(item, offset);
            T   entry;

            if (_entries.TryGet(index, out entry))
            {
                if (_comparer.Equals(entry, item))
                {
                    return(index);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
예제 #3
0
        /// <summary>
        /// Determines whether the specified key is contained.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="offset">The offset from the default index.</param>
        /// <returns>The index where the key is set; -1 otherwise.</returns>
        public int ContainsKey(TKey key, int offset)
        {
            int index = Index(key, offset);
            KeyValuePair <TKey, TValue> entry;

            if (_entries.TryGet(index, out entry))
            {
                if (_keyComparer.Equals(entry.Key, key))
                {
                    return(index);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
예제 #4
0
 /// <summary>
 /// Tries to retrieve the item at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="value">The value.</param>
 /// <returns>
 ///   <c>true</c> if the item was retrieved; otherwise, <c>false</c>.
 /// </returns>
 /// <exception cref="System.ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception>
 public bool TryGet(int index, out T value)
 {
     return(_bucket.TryGet(index, out value));
 }