RouletteDictionaryTKey, TValue Class |
Namespace: Scaleout.Collections
public sealed class RouletteDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable
The RouletteDictionaryTKey, TValue type exposes the following members.
| Name | Description | |
|---|---|---|
| RouletteDictionaryTKey, TValue |
Initializes a new instance of the dictionary that is empty,
has the default initial capacity, and uses the default equality comparer for the key type.
| |
| RouletteDictionaryTKey, TValue(IEqualityComparerTKey) |
Initializes a new instance of the dictionary that is empty,
has the default initial capacity, and uses the specified equality comparer for the key type.
| |
| RouletteDictionaryTKey, TValue(Int32) |
Initializes a new instance of the dictionary that is empty,
has the specified initial capacity, and uses the default equality comparer for the key type.
| |
| RouletteDictionaryTKey, TValue(Int32, IEqualityComparerTKey) |
Initializes a new instance of the dictionary with the specified
initial capacity and uses the equality comparer for the key type.
|
| Name | Description | |
|---|---|---|
| Count |
Gets the number of key/value pairs contained in the dictionary.
| |
| Item |
Gets or sets the value associated with the specified key.
| |
| Keys |
Gets a collection containing the keys in the dictionary.
| |
| Values |
Gets a collection containing the values in the dictionary.
|
| Name | Description | |
|---|---|---|
| Add |
Adds the specified key and value to the dictionary.
| |
| Clear |
Removes all items from the dictionary without changing the dictionary's capacity.
| |
| ContainsKey |
Determines whether the dictionary contains the specified key.
| |
| ContainsValue |
Determines whether the dictionary contains the specified value.
| |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
| GetEnumerator |
Returns an enumerator that iterates through the dictionary.
| |
| GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
| GetRandomKey |
Gets a random key from the dictionary.
| |
| GetRandomKey(FuncTValue, Boolean) |
Gets a random value from the dictionary that satisfies a condition.
| |
| GetRandomKeyAndValue |
Gets a random key-value pair from the dictionary.
| |
| GetRandomKeyAndValue(FuncTValue, Boolean) |
Gets a random key-value pair from the dictionary whose value satisfies a condition.
| |
| GetRandomValue |
Gets a random value from the dictionary.
| |
| GetRandomValue(FuncTValue, Boolean) |
Gets a random value from the dictionary that satisfies a condition.
| |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Remove |
Removes the value with the specified key from the dictionary.
| |
| RemoveRandom |
Removes a random entry from the dictionary.
| |
| RemoveRandom(FuncTValue, Boolean) |
Removes a random entry from the dictionary that satisfies a condition.
| |
| RemoveRandomAndGet |
Removes a random entry from the dictionary, returning the removed
entry as a KeyValuePair.
| |
| RemoveRandomAndGet(FuncTValue, Boolean) |
Removes a random entry from the dictionary that satisfies a condition, returning the removed
entry as a KeyValuePair.
| |
| SetAndMaintainCount |
Adds/updates the dictionary with a new value. If the operation performs an
add, a random element will be removed to make room for the new one.
| |
| ToString | Returns a string that represents the current object. (Inherited from Object.) | |
| Trim |
Trims excess capacity from the dictionary.
| |
| TryGetValue |
Gets the value associated with the specified key.
|
This dictionary is intended to be used as a building block for caches that perform random eviction. The SetAndMaintainCount(TKey, TValue) method is the primary method for this use case. It allows entries to be added/updated in the dictionary and removes a random item if the operation results in an add to prevent unbounded growth.
The collection also offers methods for retrieval and removal of random items.