/// <summary> /// Removes the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns> /// <c>true</c> if the specified value was removed; otherwise, <c>false</c>. /// </returns> public bool Remove(T value) { // ReSharper disable once AssignNullToNotNullAttribute var hashCode = Comparer.GetHashCode(value); for (var attempts = 0; attempts < _probing; attempts++) { var done = false; var result = _bucket.RemoveAt ( hashCode + attempts, found => { if (Comparer.Equals(found, value)) { done = true; return(true); } return(false); } ); if (done) { return(result); } } return(false); }
/// <summary> /// Removes the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns> /// <c>true</c> if the specified value was removed; otherwise, <c>false</c>. /// </returns> public bool Remove(T value) { var hashCode = _comparer.GetHashCode(value); for (var attempts = 0; attempts < _probing; attempts++) { var done = false; var result = _bucket.RemoveAt ( hashCode + attempts, found => { if (_comparer.Equals(found, value)) { done = true; return(true); } return(false); } ); if (done) { return(result); } } return(false); }
/// <summary> /// Attempts to retrieve and remove the next item from the back. /// </summary> /// <param name="item">The item.</param> /// <returns> /// <c>true</c> if the item was taken; otherwise, <c>false</c>. /// </returns> public bool TryTake(out T item) { if (_entries.Count > 0) { var preCount = Interlocked.Decrement(ref _preCount); if (preCount >= 0) { var index = (Interlocked.Increment(ref _indexDequeue) - 1) & (_capacity - 1); if (_entries.RemoveAt(index, out item)) { return(true); } } Interlocked.Increment(ref _preCount); } item = default(T); return(false); }
/// <summary> /// Removes the item at the specified index. /// </summary> /// <param name="index">The index.</param> /// <returns> /// <c>true</c> if the item was removed; 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 RemoveAt(int index) { return(_entries.RemoveAt(index)); }