KS.Reactor.ksAtomicDictionary< Key, Value > Class Template Reference

Wraps a Dictionary to make all read/write operations thread safe. More...

Public Member Functions

delegate Value Factory ()
 Factory delegate for creating a Value . More...
 
delegate bool ForEachCallback (KeyValuePair< Key, Value > pair)
 For each callback. More...
 
Value Get (Key k, Value defaultValue=default(Value))
 Gets the value for a key. More...
 
bool TryGetValue (Key k, out Value outValue)
 Tries to get the value for a key. More...
 
bool TryAdd (Key k, Value value)
 Tries to add the specified key and value to the dictionary. More...
 
bool GetOrAddValue (Key key, Factory factory, out Value value)
 Gets the value of a key from the dictionary. More...
 
void Clear ()
 Removes everything from the dictionary. More...
 
bool Remove (Key k)
 Removes a key/value pair from the dictionary. More...
 
bool Remove (Key k, Value v)
 Removes a key/value pair from the dictionary if the value for the key matches the given value. More...
 
bool TryRemove (Key k, out Value outValue)
 Tries to remove and return the value that has the specified key from the dictionary. More...
 
bool ContainsKey (Key k)
 Checks if a key is in the dictionary. More...
 
void ForEach (ForEachCallback callback)
 Call a delegate function on each pair in the dictionary. More...
 
void ForEachThenClear (ForEachCallback callback)
 Call a delegate function on each pair in the dictionary and then remove the pair if the callback returns true. More...
 

Properties

Value this[Key k] [get, set]
 Gets/Sets the value for a key. More...
 
Key[] Keys [get]
 Gets a collection of all keys. More...
 
Value[] Values [get]
 Gets a collection of all values. More...
 

Detailed Description

Wraps a Dictionary to make all read/write operations thread safe.

Template Parameters
Key
Value

Member Function Documentation

◆ Clear()

void KS.Reactor.ksAtomicDictionary< Key, Value >.Clear ( )

Removes everything from the dictionary.

◆ ContainsKey()

bool KS.Reactor.ksAtomicDictionary< Key, Value >.ContainsKey ( Key  k)

Checks if a key is in the dictionary.

Parameters
kKey to check.
Returns
True if the key is in the dictionary.

◆ Factory()

delegate Value KS.Reactor.ksAtomicDictionary< Key, Value >.Factory ( )

Factory delegate for creating a Value .

Returns
Value

◆ ForEach()

void KS.Reactor.ksAtomicDictionary< Key, Value >.ForEach ( ForEachCallback  callback)

Call a delegate function on each pair in the dictionary.

Parameters
callback

◆ ForEachCallback()

delegate bool KS.Reactor.ksAtomicDictionary< Key, Value >.ForEachCallback ( KeyValuePair< Key, Value >  pair)

For each callback.

Parameters
pairPair being iterated
Returns
True to remove the pair from the dictionary.

◆ ForEachThenClear()

void KS.Reactor.ksAtomicDictionary< Key, Value >.ForEachThenClear ( ForEachCallback  callback)

Call a delegate function on each pair in the dictionary and then remove the pair if the callback returns true.

Parameters
callback

◆ Get()

Value KS.Reactor.ksAtomicDictionary< Key, Value >.Get ( Key  k,
Value  defaultValue = default(Value) 
)

Gets the value for a key.

Parameters
kKey to get value for.
defaultValueDefault value to return if the key is not in the dictionary.
Returns
Value for the key.

◆ GetOrAddValue()

bool KS.Reactor.ksAtomicDictionary< Key, Value >.GetOrAddValue ( Key  key,
Factory  factory,
out Value  value 
)

Gets the value of a key from the dictionary.

Creates a new value for the key by calling a factory and adds it to the dictionary if the key was not found.

Parameters
keyKey to get value for.
factoryFactory for creating the value if the key was not found.
valueThe value for the key
Returns
True if the key was already in the dictionary, false if it was added with the factory.

◆ Remove() [1/2]

bool KS.Reactor.ksAtomicDictionary< Key, Value >.Remove ( Key  k)

Removes a key/value pair from the dictionary.

Parameters
kKey to remove.
Returns
True if they key was found and removed from the dictionary.

◆ Remove() [2/2]

bool KS.Reactor.ksAtomicDictionary< Key, Value >.Remove ( Key  k,
Value  v 
)

Removes a key/value pair from the dictionary if the value for the key matches the given value.

Parameters
kKey to remove.
vThe key/value pair will only be removed if the value for the key matches this.
Returns
True if the key/value pair was removed.

◆ TryAdd()

bool KS.Reactor.ksAtomicDictionary< Key, Value >.TryAdd ( Key  k,
Value  value 
)

Tries to add the specified key and value to the dictionary.

Parameters
kKey to add.
valueValue to add.
Returns
True if the key/value pair was added to the dictionary successfully; false if the key already exists.

◆ TryGetValue()

bool KS.Reactor.ksAtomicDictionary< Key, Value >.TryGetValue ( Key  k,
out Value  outValue 
)

Tries to get the value for a key.

Parameters
kKey to get value for.
outValueOut value.
Returns
True if succesful.

◆ TryRemove()

bool KS.Reactor.ksAtomicDictionary< Key, Value >.TryRemove ( Key  k,
out Value  outValue 
)

Tries to remove and return the value that has the specified key from the dictionary.

Parameters
kKey to get value for.
outValueThe object removed from the dictionary, or the default value of the TValue type if key does not exist.
Returns
True if the object was removed successfully; otherwise, false.

Property Documentation

◆ Keys

Key [] KS.Reactor.ksAtomicDictionary< Key, Value >.Keys
get

Gets a collection of all keys.

◆ this[Key k]

Value KS.Reactor.ksAtomicDictionary< Key, Value >.this[Key k]
getset

Gets/Sets the value for a key.

Parameters
kKey.
Returns
Value.

◆ Values

Value [] KS.Reactor.ksAtomicDictionary< Key, Value >.Values
get

Gets a collection of all values.