/// <summary> /// Returns the next item to be taken from the back without removing it. /// </summary> /// <returns>The next item to be taken from the back.</returns> /// <exception cref="System.InvalidOperationException">No more items to be taken.</exception> public T Peek() { T item; var index = Interlocked.Add(ref _indexEnqueue, 0); if (index < _capacity && index > 0 && _entries.TryGet(index, out item)) { return(item); } throw new InvalidOperationException("Empty"); }
/// <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="ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception> public bool TryGet(int index, out T value) { if (_entries.TryGet(index, out var found)) { // Null resistant found.TryGetValue(out value); // We don't donate because we didn't remove return(true); } value = default; return(false); }
/// <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) { TNeedle found; if (_entries.TryGet(index, out found)) { // Null resistant found.TryGetValue(out value); // We don't donate because we didn't remove return true; } value = default(T); return false; }
/// <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(_entries.TryGet(index, out value)); }