ImmutableInterlocked
Contains interlocked exchange mechanisms for immutable collections.
NuGet package: System.Collections.Immutable (about immutable collections and how to install)
public static TValue AddOrUpdate<TKey, TValue>(ref ImmutableDictionary location, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
Obtains the value from a dictionary after having added it or updated an existing entry.
public static TValue AddOrUpdate<TKey, TValue>(ref ImmutableDictionary location, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
Obtains the value from a dictionary after having added it or updated an existing entry.
Atomically enqueues an element to the end of a queue.
public static TValue GetOrAdd<TKey, TValue, TArg>(ref ImmutableDictionary location, TKey key, Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument)
Gets the value for the specified key from the dictionary, or if the key was not found, adds a new value to the dictionary.
public static TValue GetOrAdd<TKey, TValue>(ref ImmutableDictionary location, TKey key, Func<TKey, TValue> valueFactory)
Gets the value for the specified key from the dictionary, or if the key was not found, adds a new value to the dictionary.
public static TValue GetOrAdd<TKey, TValue>(ref ImmutableDictionary location, TKey key, TValue value)
Gets the value for the specified key from the dictionary, or if the key was not found, adds a new value to the dictionary.
public static ImmutableArray<T> InterlockedCompareExchange<T>(ref ImmutableArray location, ImmutableArray<T> value, ImmutableArray<T> comparand)
Compares two immutable arrays for equality and, if they are equal, replaces one of the arrays.
public static ImmutableArray<T> InterlockedExchange<T>(ref ImmutableArray location, ImmutableArray<T> value)
Sets an array to the specified array and returns a reference to the original array, as an atomic operation.
Sets an array to the specified array if the array has not been initialized.
Pushes a new element onto the stack.
Adds the specified key and value to the dictionary if the key is not in the dictionary.
Atomically removes and returns the specified element at the head of the queue, if the queue is not empty.
Removes an element from the top of the stack, if there is an element to remove.
public static bool TryRemove<TKey, TValue>(ref ImmutableDictionary location, TKey key, out TValue value)
Removes the element with the specified key, if the key exists.
public static bool TryUpdate<TKey, TValue>(ref ImmutableDictionary location, TKey key, TValue newValue, TValue comparisonValue)
Sets the specified key to the specified value if the specified key already is set to a specific value.
Mutates a value in-place with optimistic locking transaction semantics via a specified transformation function. The transformation is retried as many times as necessary to win the optimistic locking race.
public static bool Update<T, TArg>(ref T location, Func<T, TArg, T> transformer, TArg transformerArgument)
Mutates a value in-place with optimistic locking transaction semantics via a specified transformation function. The transformation is retried as many times as necessary to win the optimistic locking race.
public static bool Update<T>(ref ImmutableArray location, Func<ImmutableArray<T>, ImmutableArray<T>> transformer)
public static bool Update<T, TArg>(ref ImmutableArray location, Func<ImmutableArray<T>, TArg, ImmutableArray<T>> transformer, TArg transformerArgument)