Click or drag to resize

RouletteDictionaryTKey, TValue Class

A collection of keys and values that allows random entries to be retrieved or removed.
Inheritance Hierarchy
SystemObject
  Scaleout.CollectionsRouletteDictionaryTKey, TValue

Namespace:  Scaleout.Collections
Assembly:  Scaleout.Collections (in Scaleout.Collections.dll) Version: 1.0.3.0 (1.0.3.0)
Syntax
C#
public sealed class RouletteDictionary<TKey, TValue> : IDictionary<TKey, TValue>, 
	ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, 
	IEnumerable

Type Parameters

TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.

The RouletteDictionaryTKey, TValue type exposes the following members.

Constructors
  NameDescription
Public methodRouletteDictionaryTKey, 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.
Public methodRouletteDictionaryTKey, 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.
Public methodRouletteDictionaryTKey, 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.
Public methodRouletteDictionaryTKey, TValue(Int32, IEqualityComparerTKey)
Initializes a new instance of the dictionary with the specified initial capacity and uses the equality comparer for the key type.
Top
Properties
  NameDescription
Public propertyCount
Gets the number of key/value pairs contained in the dictionary.
Public propertyItem
Gets or sets the value associated with the specified key.
Public propertyKeys
Gets a collection containing the keys in the dictionary.
Public propertyValues
Gets a collection containing the values in the dictionary.
Top
Methods
  NameDescription
Public methodAdd
Adds the specified key and value to the dictionary.
Public methodClear
Removes all items from the dictionary without changing the dictionary's capacity.
Public methodContainsKey
Determines whether the dictionary contains the specified key.
Public methodContainsValue
Determines whether the dictionary contains the specified value.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the dictionary.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRandomKey
Gets a random key from the dictionary.
Public methodGetRandomKey(FuncTValue, Boolean)
Gets a random value from the dictionary that satisfies a condition.
Public methodGetRandomKeyAndValue
Gets a random key-value pair from the dictionary.
Public methodGetRandomKeyAndValue(FuncTValue, Boolean)
Gets a random key-value pair from the dictionary whose value satisfies a condition.
Public methodGetRandomValue
Gets a random value from the dictionary.
Public methodGetRandomValue(FuncTValue, Boolean)
Gets a random value from the dictionary that satisfies a condition.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodRemove
Removes the value with the specified key from the dictionary.
Public methodRemoveRandom
Removes a random entry from the dictionary.
Public methodRemoveRandom(FuncTValue, Boolean)
Removes a random entry from the dictionary that satisfies a condition.
Public methodRemoveRandomAndGet
Removes a random entry from the dictionary, returning the removed entry as a KeyValuePair.
Public methodRemoveRandomAndGet(FuncTValue, Boolean)
Removes a random entry from the dictionary that satisfies a condition, returning the removed entry as a KeyValuePair.
Public methodSetAndMaintainCount
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.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTrim
Trims excess capacity from the dictionary.
Public methodTryGetValue
Gets the value associated with the specified key.
Top
Remarks

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.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also