/// <summary> /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param> /// <returns> /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </returns> /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception> public bool Remove(T item) { var result = ImmutableHashSet <T> .Remove(item, this.Origin); this.Apply(result); return(result.Count != 0); }
/// <summary> /// Performs an atomic pop from an Immutable Hash Set /// </summary> /// <param name="hashSet">The location of the hash set to remove from</param> /// <param name="item">The item to remove</param> /// <returns>True if an item was removed, or False if the item was not found</returns> public static bool Remove <T>(ref ImmutableHashSet <T> hashSet, T item) { //**************************************** ImmutableHashSet <T> OldSet, NewSet; //**************************************** do { OldSet = hashSet; NewSet = OldSet.Remove(item); if (object.ReferenceEquals(OldSet, NewSet)) { return(false); } } while (Interlocked.CompareExchange(ref hashSet, NewSet, OldSet) != OldSet); return(true); }