/// <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 && _entries.TryGet(index, out item)) { return(item); } throw new InvalidOperationException("Empty"); }
/// <inheritdoc /> /// <summary> /// Determines whether the specified value is contained. /// </summary> /// <param name="value">The value.</param> /// <returns> /// <c>true</c> if the specified value is contained; otherwise, <c>false</c>. /// </returns> public bool Contains(T value) { // ReSharper disable once AssignNullToNotNullAttribute var hashCode = Comparer.GetHashCode(value); for (var attempts = 0; attempts < _probing; attempts++) { if (_bucket.TryGet(hashCode + attempts, out var found) && Comparer.Equals(found, value)) { return(true); } } return(false); }
/// <summary> /// Determines whether the specified value is contained. /// </summary> /// <param name="value">The value.</param> /// <returns> /// <c>true</c> if the specified value is contained; otherwise, <c>false</c>. /// </returns> public bool Contains(T value) { var hashCode = _comparer.GetHashCode(value); for (var attempts = 0; attempts < _probing; attempts++) { T found; if (_bucket.TryGet(hashCode + attempts, out found)) { if (_comparer.Equals(found, value)) { return(true); } } } return(false); }
/// <summary> /// Determines whether the specified value is contained. /// </summary> /// <param name="hashCode">The hash code to look for.</param> /// <param name="check">The value predicate.</param> /// <returns> /// <c>true</c> if the specified value is contained; otherwise, <c>false</c>. /// </returns> public bool Contains(int hashCode, Predicate <T> check) { if (check == null) { throw new ArgumentNullException(nameof(check)); } for (var attempts = 0; attempts < _probing; attempts++) { if (_bucket.TryGet(hashCode + attempts, out var found) && GetHashCode(found) == hashCode && check(found)) { return(true); } } 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)); }