LanguageExt.Core

LanguageExt.Core Concurrency AtomHashMap

Contents

class AtomHashMap <K, V> Source #

Atoms provide a way to manage shared, synchronous, independent state without locks. AtomHashMap wraps the language-ext HashMap, and makes sure all operations are atomic and thread-safe without resorting to locking

See the concurrency section of the wiki for more info.

Indexers

this [ V ] Source #

'this' accessor

Parameters

param key

Key

returns

Optional value

Properties

property AtomHashMap<K, V> Empty Source #

Creates a new atom-hashmap

property bool IsEmpty Source #

Is the map empty

property int Count Source #

Number of items in the map

property int Length Source #

Alias of Count

property IEnumerable<K> Keys Source #

Enumerable of map keys

property IEnumerable<V> Values Source #

Enumerable of map values

Methods

method IReadOnlyDictionary<K, V> ToReadOnlyDictionary () Source #

Get a IReadOnlyDictionary for this map. No mapping is required, so this is very fast.

method Unit Swap (Func<TrackingHashMap<K, V>, TrackingHashMap<K, V>> swap) Source #

Atomically swap the underlying hash-map. Allows for multiple operations on the hash-map in an entirely transactional and atomic way.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

NOTE: The change-tracking only works if you transform the TrackingHashMap provided to the Func. If you build a fresh one then it won't have any tracking. You can call map.Clear() to get to an empty map, which will also track the removals.

Parameters

param swap

Swap function, maps the current state of the AtomHashMap to a new state

method Unit SwapKey (K key, Func<V, V> swap) Source #

Atomically swap a key in the hash-map, if it exists. If it doesn't exist, nothing changes. Allows for multiple operations on the hash-map value in an entirely transactional and atomic way.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param swap

Swap function, maps the current state of a value in the AtomHashMap to a new value

method Unit SwapKey (K key, Func<Option<V>, Option<V>> swap) Source #

Atomically swap a key in the hash-map:

  • If the key doesn't exist, then None is passed to swap
  • If the key does exist, then Some(x) is passed to swap

The operation performed on the hash-map depends on the value going in and out of swap:

In Out Operation
Some(x) Some(y) SetItem(key, y)
Some(x) None Remove(key)
None Some(y) Add(key, y)
None None no-op

Allows for multiple operations on the hash-map value in an entirely transactional and atomic way.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param swap

Swap function, maps the current state of a value in the AtomHashMap to a new value

method AtomHashMap<K, V> Filter (Func<V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

returns

New map with items filtered

method Unit FilterInPlace (Func<V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param pred

Predicate

returns

New map with items filtered

method AtomHashMap<K, V> Filter (Func<K, V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

method Unit FilterInPlace (Func<K, V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param pred

Predicate

method Unit MapInPlace (Func<V, V> f) Source #

Atomically maps the map to a new map

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

returns

Mapped items in a new map

method AtomHashMap<K, U> Map <U> (Func<K, V, U> f) Source #

Atomically maps the map to a new map

Parameters

returns

Mapped items in a new map

method Unit Add (K key, V value) Source #

Atomically adds a new item to the map

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit TryAdd (K key, V value) Source #

Atomically adds a new item to the map. If the key already exists, then the new item is ignored

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit AddOrUpdate (K key, V value) Source #

Atomically adds a new item to the map. If the key already exists, the new item replaces it.

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit AddOrUpdate (K key, Func<V, V> Some, Func<V> None) Source #

Retrieve a value from the map by key, map it to a new value, put it back. If it doesn't exist, add a new one based on None result.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

method Unit AddOrUpdate (K key, Func<V, V> Some, V None) Source #

Retrieve a value from the map by key, map it to a new value, put it back. If it doesn't exist, add a new one based on None result.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

method Unit AddRange (IEnumerable<(K Key, V Value)> range) Source #

Atomically adds a range of items to the map.

Null is not allowed for a Key or a Value

Parameters

param range

Range of tuples to add

method Unit TryAddRange (IEnumerable<(K Key, V Value)> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're ignored.

Null is not allowed for a Key or a Value

Parameters

param range

Range of tuples to add

method Unit TryAddRange (IEnumerable<KeyValuePair<K, V>> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're ignored.

Null is not allowed for a Key or a Value

Parameters

param range

Range of KeyValuePairs to add

method Unit AddOrUpdateRange (IEnumerable<(K Key, V Value)> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're replaced.

Null is not allowed for a Key or a Value

Parameters

param range

Range of tuples to add

returns

New Map with the items added

method Unit AddOrUpdateRange (IEnumerable<KeyValuePair<K, V>> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're replaced.

Null is not allowed for a Key or a Value

Parameters

param range

Range of KeyValuePairs to add

method Unit Remove (K key) Source #

Atomically removes an item from the map If the key doesn't exists, the request is ignored.

Parameters

param key

Key

method Option<V> Find (K value) Source #

Retrieve a value from the map by key

Parameters

param key

Key to find

returns

Found value

method IEnumerable<V> FindSeq (K key) Source #

Retrieve a value from the map by key as an enumerable

Parameters

param key

Key to find

returns

Found value

method R Find <R> (K key, Func<V, R> Some, Func<R> None) Source #

Retrieve a value from the map by key and pattern match the result.

Parameters

param key

Key to find

returns

Found value

method V FindOrAdd (K key, Func<V> None) Source #

Try to find the key in the map, if it doesn't exist, add a new item by invoking the delegate provided.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

param None

Delegate to get the value

returns

Added value

method V FindOrAdd (K key, V value) Source #

Try to find the key in the map, if it doesn't exist, add a new item provided.

Parameters

param key

Key to find

param value

Delegate to get the value

returns

Added value

method Option<V> FindOrMaybeAdd (K key, Func<Option<V>> None) Source #

Try to find the key in the map, if it doesn't exist, add a new item by invoking the delegate provided.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

param None

Delegate to get the value

returns

Added value

method Option<V> FindOrMaybeAdd (K key, Option<V> None) Source #

Try to find the key in the map, if it doesn't exist, add a new item by invoking the delegate provided.

Parameters

param key

Key to find

param None

Delegate to get the value

returns

Added value

method Unit SetItem (K key, V value) Source #

Atomically updates an existing item

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit SetItem (K key, Func<V, V> Some) Source #

Retrieve a value from the map by key, map it to a new value, put it back.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to set

method Unit TrySetItem (K key, V value) Source #

Atomically updates an existing item, unless it doesn't exist, in which case it is ignored

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit TrySetItem (K key, Func<V, V> Some) Source #

Atomically sets an item by first retrieving it, applying a map, and then putting it back. Silently fails if the value doesn't exist

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to set

param Some

delegate to map the existing value to a new one before setting

method bool ContainsKey (K key) Source #

Checks for existence of a key in the map

Parameters

param key

Key to check

returns

True if an item with the key supplied is in the map

method bool Contains (K key, V value) Source #

Checks for existence of a key in the map

Parameters

param key

Key to check

returns

True if an item with the key supplied is in the map

method bool Contains (V value) Source #

Checks for existence of a value in the map

Parameters

param value

Value to check

returns

True if an item with the value supplied is in the map

method bool Contains <EqV> (V value) Source #

where EqV : struct, Eq<V>

Checks for existence of a value in the map

Parameters

param value

Value to check

returns

True if an item with the value supplied is in the map

method bool Contains <EqV> (K key, V value) Source #

where EqV : struct, Eq<V>

Checks for existence of a key in the map

Parameters

param key

Key to check

returns

True if an item with the key supplied is in the map

method Unit Clear () Source #

Clears all items from the map

method Unit AddRange (IEnumerable<KeyValuePair<K, V>> pairs) Source #

Atomically adds a range of items to the map

Parameters

param pairs

Range of KeyValuePairs to add

method Unit SetItems (IEnumerable<KeyValuePair<K, V>> items) Source #

Atomically sets a series of items using the KeyValuePairs provided

Parameters

param items

Items to set

method Unit SetItems (IEnumerable<(K Key, V Value)> items) Source #

Atomically sets a series of items using the Tuples provided.

Parameters

param items

Items to set

method Unit TrySetItems (IEnumerable<KeyValuePair<K, V>> items) Source #

Atomically sets a series of items using the KeyValuePairs provided. If any of the items don't exist then they're silently ignored.

Parameters

param items

Items to set

method Unit TrySetItems (IEnumerable<(K Key, V Value)> items) Source #

Atomically sets a series of items using the Tuples provided If any of the items don't exist then they're silently ignored.

Parameters

param items

Items to set

method Unit TrySetItems (IEnumerable<K> keys, Func<V, V> Some) Source #

Atomically sets a series of items using the keys provided to find the items and the Some delegate maps to a new value. If the items don't exist then they're silently ignored.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param keys

Keys of items to set

param Some

Function map the existing item to a new one

method Unit RemoveRange (IEnumerable<K> keys) Source #

Atomically removes a set of keys from the map

Parameters

param keys

Keys to remove

method bool Contains (KeyValuePair<K, V> pair) Source #

Returns true if a Key/Value pair exists in the map

Parameters

param pair

Pair to find

returns

True if exists, false otherwise

method IReadOnlyDictionary<K, V> ToDictionary () Source #

Convert the map to an IDictionary

This is effectively a zero cost operation, not even a single allocation

method HashMap<K, V> ToHashMap () Source #

Convert to a HashMap

This is effectively a zero cost operation, not even a single allocation

method IDictionary<KR, VR> ToDictionary <KR, VR> ( Func<(K Key, V Value), KR> keySelector, Func<(K Key, V Value), VR> valueSelector) Source #

where KR : notnull

Map the map the a dictionary

method IEnumerator<(K Key, V Value)> GetEnumerator () Source #

GetEnumerator - IEnumerable interface

method Seq<(K Key, V Value)> ToSeq () Source #

method string ToString () Source #

Format the collection as [(key: value), (key: value), (key: value), ...] The ellipsis is used for collections over 50 items To get a formatted string with all the items, use ToFullString or ToFullArrayString.

method string ToFullString (string separator = ", ") Source #

Format the collection as (key: value), (key: value), (key: value), ...

method string ToFullArrayString (string separator = ", ") Source #

Format the collection as [(key: value), (key: value), (key: value), ...]

method IEnumerable<(K Key, V Value)> AsEnumerable () Source #

method Unit Append (AtomHashMap<K, V> rhs) Source #

method Unit Append (HashMap<K, V> rhs) Source #

method Unit Subtract (AtomHashMap<K, V> rhs) Source #

method Unit Subtract (HashMap<K, V> rhs) Source #

method bool IsProperSubsetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a proper subset of this set

Parameters

returns

True if 'other' is a proper subset of this set

method bool IsProperSubsetOf (IEnumerable<K> other) Source #

Returns True if 'other' is a proper subset of this set

Parameters

returns

True if 'other' is a proper subset of this set

method bool IsProperSupersetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a proper superset of this set

Parameters

returns

True if 'other' is a proper superset of this set

method bool IsProperSupersetOf (IEnumerable<K> other) Source #

Returns True if 'other' is a proper superset of this set

Parameters

returns

True if 'other' is a proper superset of this set

method bool IsSubsetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSubsetOf (IEnumerable<K> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSubsetOf (HashMap<K, V> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSupersetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSupersetOf (IEnumerable<K> rhs) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method Unit Intersect (IEnumerable<K> rhs) Source #

Returns the elements that are in both this and other

method Unit Intersect (IEnumerable<(K Key, V Value)> rhs) Source #

Returns the elements that are in both this and other

method Unit Intersect (IEnumerable<(K Key, V Value)> rhs, WhenMatched<K, V, V, V> Merge) Source #

Returns the elements that are in both this and other

method Unit Intersect (HashMap<K, V> rhs, WhenMatched<K, V, V, V> Merge) Source #

Returns the elements that are in both this and other

method bool Overlaps (IEnumerable<(K Key, V Value)> other) Source #

Returns True if other overlaps this set

method bool Overlaps (IEnumerable<K> other) Source #

Returns True if other overlaps this set

method Unit Except (IEnumerable<K> rhs) Source #

Returns this - rhs. Only the items in this that are not in rhs will be returned.

method Unit Except (IEnumerable<(K Key, V Value)> rhs) Source #

Returns this - other. Only the items in this that are not in other will be returned.

method Unit SymmetricExcept (HashMap<K, V> rhs) Source #

Only items that are in one set or the other will be returned. If an item is in both, it is dropped.

method Unit SymmetricExcept (IEnumerable<(K Key, V Value)> rhs) Source #

Only items that are in one set or the other will be returned. If an item is in both, it is dropped.

method Unit Union (IEnumerable<(K, V)> rhs) Source #

Finds the union of two sets and produces a new set with the results

Parameters

param other

Other set to union with

returns

A set which contains all items from both sets

method Unit Union (IEnumerable<(K Key, V Value)> rhs, WhenMatched<K, V, V, V> Merge) Source #

Union two maps.

The WhenMatched merge function is called when keys are present in both map to allow resolving to a sensible value.

method Unit Union <W> (IEnumerable<(K Key, W Value)> rhs, WhenMissing<K, W, V> MapRight, WhenMatched<K, V, W, V> Merge) Source #

Union two maps.

The WhenMatched merge function is called when keys are present in both map to allow resolving to a sensible value.

The WhenMissing function is called when there is a key in the right-hand side, but not the left-hand-side. This allows the V2 value-type to be mapped to the target V value-type.

method bool Equals (object? obj) Source #

Equality of keys and values with EqDefault<V> used for values

method bool Equals (AtomHashMap<K, V>? other) Source #

Equality of keys and values with EqDefault<V> used for values

method bool Equals (HashMap<K, V> other) Source #

Equality of keys and values with EqDefault<V> used for values

method bool EqualsKeys (AtomHashMap<K, V> other) Source #

Equality of keys only

method bool EqualsKeys (HashMap<K, V> other) Source #

Equality of keys only

method int GetHashCode () Source #

method AtomHashMap<K, U> Select <U> (Func<V, U> f) Source #

Atomically maps the map to a new map

Parameters

returns

Mapped items in a new map

method AtomHashMap<K, U> Select <U> (Func<K, V, U> f) Source #

Atomically maps the map to a new map

Parameters

returns

Mapped items in a new map

method AtomHashMap<K, V> Where (Func<V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

returns

New map with items filtered

method AtomHashMap<K, V> Where (Func<K, V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

returns

New map with items filtered

method bool ForAll (Func<K, V, bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool ForAll (Func<(K Key, V Value), bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool ForAll (Func<KeyValuePair<K, V>, bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool ForAll (Func<V, bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<K, V, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<Tuple<K, V>, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<(K Key, V Value), bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<KeyValuePair<K, V>, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<V, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method Unit Iter (Action<K, V> action) Source #

Atomically iterate through all key/value pairs in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method Unit Iter (Action<V> action) Source #

Atomically iterate through all values in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method Unit Iter (Action<(K Key, V Value)> action) Source #

Atomically iterate through all key/value pairs (as tuples) in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method Unit Iter (Action<KeyValuePair<K, V>> action) Source #

Atomically iterate through all key/value pairs in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method S Fold <S> (S state, Func<S, K, V, S> folder) Source #

Atomically folds all items in the map (in order) using the folder function provided.

Parameters

type S

State type

param state

Initial state

param folder

Fold function

returns

Folded state

method S Fold <S> (S state, Func<S, V, S> folder) Source #

Atomically folds all items in the map (in order) using the folder function provided.

Parameters

type S

State type

param state

Initial state

param folder

Fold function

returns

Folded state

Operators

operator == (AtomHashMap<K, V> lhs, AtomHashMap<K, V> rhs) Source #

Equality of keys and values with EqDefault<V> used for values

operator == (AtomHashMap<K, V> lhs, HashMap<K, V> rhs) Source #

Equality of keys and values with EqDefault<V> used for values

operator == (HashMap<K, V> lhs, AtomHashMap<K, V> rhs) Source #

Equality of keys and values with EqDefault<V> used for values

operator != (AtomHashMap<K, V> lhs, AtomHashMap<K, V> rhs) Source #

In-equality of keys and values with EqDefault<V> used for values

operator != (AtomHashMap<K, V> lhs, HashMap<K, V> rhs) Source #

In-equality of keys and values with EqDefault<V> used for values

operator != (HashMap<K, V> lhs, AtomHashMap<K, V> rhs) Source #

In-equality of keys and values with EqDefault<V> used for values

class AtomHashMap <EqK, K, V> Source #

where EqK : struct, Eq<K>

Atoms provide a way to manage shared, synchronous, independent state without locks. AtomHashMap wraps the language-ext HashMap, and makes sure all operations are atomic and thread-safe without resorting to locking

See the concurrency section of the wiki for more info.

Indexers

this [ V ] Source #

'this' accessor

Parameters

param key

Key

returns

Optional value

Properties

property AtomHashMap<EqK, K, V> Empty Source #

Creates a new atom-hashmap

property bool IsEmpty Source #

Is the map empty

property int Count Source #

Number of items in the map

property int Length Source #

Alias of Count

property IEnumerable<K> Keys Source #

Enumerable of map keys

property IEnumerable<V> Values Source #

Enumerable of map values

Methods

method IReadOnlyDictionary<K, V> ToReadOnlyDictionary () Source #

Get a IReadOnlyDictionary for this map. No mapping is required, so this is very fast.

method Unit Swap (Func<TrackingHashMap<EqK, K, V>, TrackingHashMap<EqK, K, V>> swap) Source #

Atomically swap the underlying hash-map. Allows for multiple operations on the hash-map in an entirely transactional and atomic way.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

NOTE: The change-tracking only works if you transform the TrackingHashMap provided to the Func. If you build a fresh one then it won't have any tracking. You can call map.Clear() to get to an empty map, which will also track the removals.

Parameters

param swap

Swap function, maps the current state of the AtomHashMap to a new state

method Unit SwapKey (K key, Func<V, V> swap) Source #

Atomically swap a key in the hash-map, if it exists. If it doesn't exist, nothing changes. Allows for multiple operations on the hash-map value in an entirely transactional and atomic way.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param swap

Swap function, maps the current state of a value in the AtomHashMap to a new value

method Unit SwapKey (K key, Func<Option<V>, Option<V>> swap) Source #

Atomically swap a key in the hash-map:

  • If the key doesn't exist, then None is passed to swap
  • If the key does exist, then Some(x) is passed to swap

The operation performed on the hash-map depends on the value going in and out of swap:

In Out Operation
Some(x) Some(y) SetItem(key, y)
Some(x) None Remove(key)
None Some(y) Add(key, y)
None None no-op

Allows for multiple operations on the hash-map value in an entirely transactional and atomic way.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param swap

Swap function, maps the current state of a value in the AtomHashMap to a new value

method AtomHashMap<EqK, K, V> Filter (Func<V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

returns

New map with items filtered

method Unit FilterInPlace (Func<V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param pred

Predicate

returns

New map with items filtered

method AtomHashMap<EqK, K, V> Filter (Func<K, V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

method Unit FilterInPlace (Func<K, V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param pred

Predicate

method Unit MapInPlace (Func<V, V> f) Source #

Atomically maps the map to a new map

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

returns

Mapped items in a new map

method AtomHashMap<EqK, K, U> Map <U> (Func<K, V, U> f) Source #

Atomically maps the map to a new map

Parameters

returns

Mapped items in a new map

method Unit Add (K key, V value) Source #

Atomically adds a new item to the map

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit TryAdd (K key, V value) Source #

Atomically adds a new item to the map. If the key already exists, then the new item is ignored

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit AddOrUpdate (K key, V value) Source #

Atomically adds a new item to the map. If the key already exists, the new item replaces it.

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit AddOrUpdate (K key, Func<V, V> Some, Func<V> None) Source #

Retrieve a value from the map by key, map it to a new value, put it back. If it doesn't exist, add a new one based on None result.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

method Unit AddOrUpdate (K key, Func<V, V> Some, V None) Source #

Retrieve a value from the map by key, map it to a new value, put it back. If it doesn't exist, add a new one based on None result.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

method Unit AddRange (IEnumerable<(K Key, V Value)> range) Source #

Atomically adds a range of items to the map.

Null is not allowed for a Key or a Value

Parameters

param range

Range of tuples to add

method Unit TryAddRange (IEnumerable<(K Key, V Value)> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're ignored.

Null is not allowed for a Key or a Value

Parameters

param range

Range of tuples to add

method Unit TryAddRange (IEnumerable<KeyValuePair<K, V>> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're ignored.

Null is not allowed for a Key or a Value

Parameters

param range

Range of KeyValuePairs to add

method Unit AddOrUpdateRange (IEnumerable<(K Key, V Value)> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're replaced.

Null is not allowed for a Key or a Value

Parameters

param range

Range of tuples to add

returns

New Map with the items added

method Unit AddOrUpdateRange (IEnumerable<KeyValuePair<K, V>> range) Source #

Atomically adds a range of items to the map. If any of the keys exist already then they're replaced.

Null is not allowed for a Key or a Value

Parameters

param range

Range of KeyValuePairs to add

method Unit Remove (K key) Source #

Atomically removes an item from the map If the key doesn't exists, the request is ignored.

Parameters

param key

Key

method Option<V> Find (K value) Source #

Retrieve a value from the map by key

Parameters

param key

Key to find

returns

Found value

method IEnumerable<V> FindSeq (K key) Source #

Retrieve a value from the map by key as an enumerable

Parameters

param key

Key to find

returns

Found value

method R Find <R> (K key, Func<V, R> Some, Func<R> None) Source #

Retrieve a value from the map by key and pattern match the result.

Parameters

param key

Key to find

returns

Found value

method V FindOrAdd (K key, Func<V> None) Source #

Try to find the key in the map, if it doesn't exist, add a new item by invoking the delegate provided.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

param None

Delegate to get the value

returns

Added value

method V FindOrAdd (K key, V value) Source #

Try to find the key in the map, if it doesn't exist, add a new item provided.

Parameters

param key

Key to find

param value

Delegate to get the value

returns

Added value

method Option<V> FindOrMaybeAdd (K key, Func<Option<V>> None) Source #

Try to find the key in the map, if it doesn't exist, add a new item by invoking the delegate provided.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to find

param None

Delegate to get the value

returns

Added value

method Option<V> FindOrMaybeAdd (K key, Option<V> None) Source #

Try to find the key in the map, if it doesn't exist, add a new item by invoking the delegate provided.

Parameters

param key

Key to find

param None

Delegate to get the value

returns

Added value

method Unit SetItem (K key, V value) Source #

Atomically updates an existing item

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit SetItem (K key, Func<V, V> Some) Source #

Retrieve a value from the map by key, map it to a new value, put it back.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to set

method Unit TrySetItem (K key, V value) Source #

Atomically updates an existing item, unless it doesn't exist, in which case it is ignored

Null is not allowed for a Key or a Value

Parameters

param key

Key

param value

Value

method Unit TrySetItem (K key, Func<V, V> Some) Source #

Atomically sets an item by first retrieving it, applying a map, and then putting it back. Silently fails if the value doesn't exist

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param key

Key to set

param Some

delegate to map the existing value to a new one before setting

method bool ContainsKey (K key) Source #

Checks for existence of a key in the map

Parameters

param key

Key to check

returns

True if an item with the key supplied is in the map

method bool Contains (K key, V value) Source #

Checks for existence of a key in the map

Parameters

param key

Key to check

returns

True if an item with the key supplied is in the map

method bool Contains (V value) Source #

Checks for existence of a value in the map

Parameters

param value

Value to check

returns

True if an item with the value supplied is in the map

method bool Contains <EqV> (V value) Source #

where EqV : struct, Eq<V>

Checks for existence of a value in the map

Parameters

param value

Value to check

returns

True if an item with the value supplied is in the map

method bool Contains <EqV> (K key, V value) Source #

where EqV : struct, Eq<V>

Checks for existence of a key in the map

Parameters

param key

Key to check

returns

True if an item with the key supplied is in the map

method Unit Clear () Source #

Clears all items from the map

method Unit AddRange (IEnumerable<KeyValuePair<K, V>> pairs) Source #

Atomically adds a range of items to the map

Parameters

param pairs

Range of KeyValuePairs to add

method Unit SetItems (IEnumerable<KeyValuePair<K, V>> items) Source #

Atomically sets a series of items using the KeyValuePairs provided

Parameters

param items

Items to set

method Unit SetItems (IEnumerable<(K Key, V Value)> items) Source #

Atomically sets a series of items using the Tuples provided.

Parameters

param items

Items to set

method Unit TrySetItems (IEnumerable<KeyValuePair<K, V>> items) Source #

Atomically sets a series of items using the KeyValuePairs provided. If any of the items don't exist then they're silently ignored.

Parameters

param items

Items to set

method Unit TrySetItems (IEnumerable<(K Key, V Value)> items) Source #

Atomically sets a series of items using the Tuples provided If any of the items don't exist then they're silently ignored.

Parameters

param items

Items to set

method Unit TrySetItems (IEnumerable<K> keys, Func<V, V> Some) Source #

Atomically sets a series of items using the keys provided to find the items and the Some delegate maps to a new value. If the items don't exist then they're silently ignored.

Any functions passed as arguments may be run multiple times if there are multiple threads competing to update this data structure. Therefore the functions must spend as little time performing the injected behaviours as possible to avoid repeated attempts

Parameters

param keys

Keys of items to set

param Some

Function map the existing item to a new one

method Unit RemoveRange (IEnumerable<K> keys) Source #

Atomically removes a set of keys from the map

Parameters

param keys

Keys to remove

method bool Contains (KeyValuePair<K, V> pair) Source #

Returns true if a Key/Value pair exists in the map

Parameters

param pair

Pair to find

returns

True if exists, false otherwise

method IReadOnlyDictionary<K, V> ToDictionary () Source #

Convert the map to an IDictionary

This is effectively a zero cost operation, not even a single allocation

method HashMap<EqK, K, V> ToHashMap () Source #

Convert to a HashMap

This is effectively a zero cost operation, not even a single allocation

method IDictionary<KR, VR> ToDictionary <KR, VR> ( Func<(K Key, V Value), KR> keySelector, Func<(K Key, V Value), VR> valueSelector) Source #

where KR : notnull

Map the map the a dictionary

method IEnumerator<(K Key, V Value)> GetEnumerator () Source #

GetEnumerator - IEnumerable interface

method Seq<(K Key, V Value)> ToSeq () Source #

method string ToString () Source #

Format the collection as [(key: value), (key: value), (key: value), ...] The ellipsis is used for collections over 50 items To get a formatted string with all the items, use ToFullString or ToFullArrayString.

method string ToFullString (string separator = ", ") Source #

Format the collection as (key: value), (key: value), (key: value), ...

method string ToFullArrayString (string separator = ", ") Source #

Format the collection as [(key: value), (key: value), (key: value), ...]

method IEnumerable<(K Key, V Value)> AsEnumerable () Source #

method Unit Append (AtomHashMap<EqK, K, V> rhs) Source #

method Unit Append (HashMap<EqK, K, V> rhs) Source #

method Unit Subtract (AtomHashMap<EqK, K, V> rhs) Source #

method Unit Subtract (HashMap<EqK, K, V> rhs) Source #

method bool IsProperSubsetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a proper subset of this set

Parameters

returns

True if 'other' is a proper subset of this set

method bool IsProperSubsetOf (IEnumerable<K> other) Source #

Returns True if 'other' is a proper subset of this set

Parameters

returns

True if 'other' is a proper subset of this set

method bool IsProperSupersetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a proper superset of this set

Parameters

returns

True if 'other' is a proper superset of this set

method bool IsProperSupersetOf (IEnumerable<K> other) Source #

Returns True if 'other' is a proper superset of this set

Parameters

returns

True if 'other' is a proper superset of this set

method bool IsSubsetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSubsetOf (IEnumerable<K> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSubsetOf (HashMap<EqK, K, V> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSupersetOf (IEnumerable<(K Key, V Value)> other) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method bool IsSupersetOf (IEnumerable<K> rhs) Source #

Returns True if 'other' is a superset of this set

Parameters

returns

True if 'other' is a superset of this set

method Unit Intersect (IEnumerable<K> rhs) Source #

Returns the elements that are in both this and other

method Unit Intersect (IEnumerable<(K Key, V Value)> rhs) Source #

Returns the elements that are in both this and other

method Unit Intersect (IEnumerable<(K Key, V Value)> rhs, WhenMatched<K, V, V, V> Merge) Source #

Returns the elements that are in both this and other

method Unit Intersect (HashMap<EqK, K, V> rhs, WhenMatched<K, V, V, V> Merge) Source #

Returns the elements that are in both this and other

method bool Overlaps (IEnumerable<(K Key, V Value)> other) Source #

Returns True if other overlaps this set

method bool Overlaps (IEnumerable<K> other) Source #

Returns True if other overlaps this set

method Unit Except (IEnumerable<K> rhs) Source #

Returns this - rhs. Only the items in this that are not in rhs will be returned.

method Unit Except (IEnumerable<(K Key, V Value)> rhs) Source #

Returns this - other. Only the items in this that are not in other will be returned.

method Unit SymmetricExcept (HashMap<EqK, K, V> rhs) Source #

Only items that are in one set or the other will be returned. If an item is in both, it is dropped.

method Unit SymmetricExcept (IEnumerable<(K Key, V Value)> rhs) Source #

Only items that are in one set or the other will be returned. If an item is in both, it is dropped.

method Unit Union (IEnumerable<(K, V)> rhs) Source #

Finds the union of two sets and produces a new set with the results

Parameters

param other

Other set to union with

returns

A set which contains all items from both sets

method Unit Union (IEnumerable<(K Key, V Value)> rhs, WhenMatched<K, V, V, V> Merge) Source #

Union two maps.

The WhenMatched merge function is called when keys are present in both map to allow resolving to a sensible value.

method Unit Union <W> (IEnumerable<(K Key, W Value)> rhs, WhenMissing<K, W, V> MapRight, WhenMatched<K, V, W, V> Merge) Source #

Union two maps.

The WhenMatched merge function is called when keys are present in both map to allow resolving to a sensible value.

The WhenMissing function is called when there is a key in the right-hand side, but not the left-hand-side. This allows the V2 value-type to be mapped to the target V value-type.

method bool Equals (object? obj) Source #

Equality of keys and values with EqDefault<V> used for values

method bool Equals (AtomHashMap<EqK, K, V>? other) Source #

Equality of keys and values with EqDefault<V> used for values

method bool Equals (HashMap<EqK, K, V> other) Source #

Equality of keys and values with EqDefault<V> used for values

method bool EqualsKeys (AtomHashMap<EqK, K, V> other) Source #

Equality of keys only

method bool EqualsKeys (HashMap<EqK, K, V> other) Source #

Equality of keys only

method int GetHashCode () Source #

method AtomHashMap<EqK, K, U> Select <U> (Func<V, U> f) Source #

Atomically maps the map to a new map

Parameters

returns

Mapped items in a new map

method AtomHashMap<EqK, K, U> Select <U> (Func<K, V, U> f) Source #

Atomically maps the map to a new map

Parameters

returns

Mapped items in a new map

method AtomHashMap<EqK, K, V> Where (Func<V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

returns

New map with items filtered

method AtomHashMap<EqK, K, V> Where (Func<K, V, bool> pred) Source #

Atomically filter out items that return false when a predicate is applied

Parameters

param pred

Predicate

returns

New map with items filtered

method bool ForAll (Func<K, V, bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool ForAll (Func<(K Key, V Value), bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool ForAll (Func<KeyValuePair<K, V>, bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool ForAll (Func<V, bool> pred) Source #

Return true if all items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<K, V, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<Tuple<K, V>, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<(K Key, V Value), bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<KeyValuePair<K, V>, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method bool Exists (Func<V, bool> pred) Source #

Return true if any items in the map return true when the predicate is applied

Parameters

param pred

Predicate

returns

True if all items in the map return true when the predicate is applied

method Unit Iter (Action<K, V> action) Source #

Atomically iterate through all key/value pairs in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method Unit Iter (Action<V> action) Source #

Atomically iterate through all values in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method Unit Iter (Action<(K Key, V Value)> action) Source #

Atomically iterate through all key/value pairs (as tuples) in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method Unit Iter (Action<KeyValuePair<K, V>> action) Source #

Atomically iterate through all key/value pairs in the map (in order) and execute an action on each

Parameters

param action

Action to execute

returns

Unit

method S Fold <S> (S state, Func<S, K, V, S> folder) Source #

Atomically folds all items in the map (in order) using the folder function provided.

Parameters

type S

State type

param state

Initial state

param folder

Fold function

returns

Folded state

method S Fold <S> (S state, Func<S, V, S> folder) Source #

Atomically folds all items in the map (in order) using the folder function provided.

Parameters

type S

State type

param state

Initial state

param folder

Fold function

returns

Folded state

Operators

operator == (AtomHashMap<EqK, K, V> lhs, AtomHashMap<EqK, K, V> rhs) Source #

Equality of keys and values with EqDefault<V> used for values

operator == (AtomHashMap<EqK, K, V> lhs, HashMap<EqK, K, V> rhs) Source #

Equality of keys and values with EqDefault<V> used for values

operator == (HashMap<EqK, K, V> lhs, AtomHashMap<EqK, K, V> rhs) Source #

Equality of keys and values with EqDefault<V> used for values

operator != (AtomHashMap<EqK, K, V> lhs, AtomHashMap<EqK, K, V> rhs) Source #

In-equality of keys and values with EqDefault<V> used for values

operator != (AtomHashMap<EqK, K, V> lhs, HashMap<EqK, K, V> rhs) Source #

In-equality of keys and values with EqDefault<V> used for values

operator != (HashMap<EqK, K, V> lhs, AtomHashMap<EqK, K, V> rhs) Source #

In-equality of keys and values with EqDefault<V> used for values

class AtomHashMap Source #

Atoms provide a way to manage shared, synchronous, independent state without locks. AtomHashMap wraps the language-ext HashMap, and makes sure all operations are atomic and thread-safe without resorting to locking

See the concurrency section of the wiki for more info.

Methods

method AtomHashMap<K, V> ToAtom <K, V> (this HashMap<K, V> self) Source #

class AtomHashMap Source #

Atoms provide a way to manage shared, synchronous, independent state without locks. AtomHashMap wraps the language-ext HashMap, and makes sure all operations are atomic and thread-safe without resorting to locking

See the concurrency section of the wiki for more info.

Methods

method AtomHashMap<EqK, K, V> ToAtom <EqK, K, V> (this HashMap<EqK, K, V> self) Source #

where EqK : struct, Eq<K>

delegate AtomHashMapChangeEvent <K, V> Source #

Event sent from the AtomHashMap type whenever an operation successfully modifies the underlying data

Parameters

type K

Key type

type V

Value type

delegate AtomHashMapChangeEvent <EqK, K, V> Source #

where EqK : struct, Eq<K>

Event sent from the AtomHashMap type whenever an operation successfully modifies the underlying data

Parameters

type K

Key type

type V

Value type