Class DictionaryStore<TKey, TValue>
A Key->Value store that will be incrementally saved on the HDD. Thread-safe and process-safe.
public class DictionaryStore<TKey, TValue> : Store<KeyValuePair<TKey, TValue>>, IDisposable
Type Parameters
TKey
The type of the key.
TValue
The type of the value.
- Inheritance
-
Store<KeyValuePair<TKey, TValue>>DictionaryStore<TKey, TValue>
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
DictionaryStore(Stream)
public DictionaryStore(Stream stream)
Parameters
stream
Stream
Fields
loadedIdMap
protected readonly Dictionary<TKey, TValue> loadedIdMap
Field Value
- Dictionary<TKey, TValue>
unsavedIdMap
protected readonly Dictionary<TKey, DictionaryStore<TKey, TValue>.UnsavedIdMapEntry> unsavedIdMap
Field Value
- Dictionary<TKey, DictionaryStore<TKey, TValue>.UnsavedIdMapEntry>
Properties
this[TKey]
Gets or sets the item with the specified key.
public TValue this[TKey key] { get; set; }
Parameters
key
TKeyThe key of the item to get or set.
Property Value
- TValue
The item to get or set.
Exceptions
Methods
AddLoaded(KeyValuePair<TKey, TValue>)
Adds a value that has already been saved in the store (saved state).
protected override void AddLoaded(KeyValuePair<TKey, TValue> item)
Parameters
item
KeyValuePair<TKey, TValue>The item.
AddUnsaved(KeyValuePair<TKey, TValue>, int)
Adds a value that has not yet been saved in the store (pending state).
protected override void AddUnsaved(KeyValuePair<TKey, TValue> item, int currentTransaction)
Parameters
item
KeyValuePair<TKey, TValue>The item.
currentTransaction
int
Contains(TKey)
Gets or sets the item with the specified key.
public bool Contains(TKey key)
Parameters
key
TKeyThe key of the item to get or set.
Returns
- bool
The item to get or set.
Exceptions
GetPendingItems(int)
Gets the list of pending items for a given transaction index.
protected override IEnumerable<KeyValuePair<TKey, TValue>> GetPendingItems(int currentTransaction)
Parameters
currentTransaction
int
Returns
- IEnumerable<KeyValuePair<TKey, TValue>>
GetValues()
Gets the values stored including unsaved.
public KeyValuePair<TKey, TValue>[] GetValues()
Returns
- KeyValuePair<TKey, TValue>[]
Values stored including unsaved.
RemoveUnsaved(KeyValuePair<TKey, TValue>, int)
Removes a value that has not yet been saved (pending state).
protected override void RemoveUnsaved(KeyValuePair<TKey, TValue> item, int currentTransaction)
Parameters
item
KeyValuePair<TKey, TValue>The item.
currentTransaction
int
ResetInternal()
Resets the store to an empty state, to be implemented by subclasses if necessary.
protected override void ResetInternal()
SearchValues(Func<KeyValuePair<TKey, TValue>, bool>)
public IEnumerable<KeyValuePair<TKey, TValue>> SearchValues(Func<KeyValuePair<TKey, TValue>, bool> predicate)
Parameters
predicate
Func<KeyValuePair<TKey, TValue>, bool>
Returns
- IEnumerable<KeyValuePair<TKey, TValue>>
TryGetValue(TKey, out TValue)
Tries to get the value from its key.
public bool TryGetValue(TKey key, out TValue value)
Parameters
key
TKeyThe key.
value
TValueThe value.