Class StateMap<TKey, TState>
- Namespace
- SodaFlow.Collections
- Assembly
- SodaFlow.Core.Collections.dll
A view of the mutable part of each item that other code cannot change. The key comes from the immutable part.
[PublicAPI]
public abstract class StateMap<TKey, TState> where TKey : notnull
Type Parameters
TKeyThe type of the keys.
TStateThe type of the mutable part of an item.
- Inheritance
-
StateMap<TKey, TState>
- Inherited Members
- Extension Methods
Remarks
This type selects the storage strategy. Each implementation must obey this contract:
A value returned by an instance never changes for the lifetime of that instance.
In a transaction, SodaFlow reads the value of a cell from before that transaction. When a snapshot from before points to storage that other code changed, those reads give a future value and no message. Thus, an implementation that changes its storage in position must give a version to that storage and must answer an older instance from a record. It must not answer with the live map.
A lookup is a TryGet and not an optional value, because this
assembly does not reference SodaFlow.Functional. Each language wrapper
adds a Lookup above this type, and that Lookup answers
with the optional type of its language.
Properties
- Count
The number of items in this version of the map.
- Keys
The keys in this version of the map, in no particular order.
- Pairs
Each key with its state, in no sequence. This is one read of the map and not one lookup for each key.
Methods
- ContainsKey(TKey)
True when this version of the map has a key.
- TryGetState(TKey, out TState?)
Returns the state for a key, when there is one.