Class ArrayDictionary<T>
Represents a dictionary with non-negative integers as keys.
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Collections
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
public class ArrayDictionary<T> : IEnumerable<KeyValuePair<int, T>>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of a value. |
Remarks
This structure is efficient when the keys are zero-based and consecutive, since the dictionary is represented by an array under the hood.
Constructors
ArrayDictionary()
Initializes a new instance of the ArrayDictionary<T> class.
Declaration
public ArrayDictionary()
ArrayDictionary(Int32)
Initializes a new instance of the ArrayDictionary<T> class with a given capacity.
Declaration
public ArrayDictionary(int capacity)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The capacity. |
Properties
Item[Int32]
Gets or sets the value associated with a given key.
Declaration
public T this[int key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | key | The key of the value to get or set. |
Property Value
Type | Description |
---|---|
T | The value associated with the specified key. |
Methods
Add(Int32, T)
Adds a given key and value to the dictionary.
Declaration
public void Add(int key, T value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | key | The key of the element to add. |
T | value | The value of the element to add. The value can be null for reference types. |
ContainsKey(Int32)
Determines whether the dictionary contains a given key.
Declaration
public bool ContainsKey(int key)
Parameters
Type | Name | Description |
---|---|---|
Int32 | key | The key to locate. |
Returns
Type | Description |
---|---|
Boolean | true if the dictionary contains an element with the specified key; otherwise, false. |
GetEnumerator()
Returns an enumerator that iterates through the dictionary in ascending key order.
Declaration
public IEnumerator<KeyValuePair<int, T>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<KeyValuePair<Int32, T>> | An enumerator for the dictionary. |
TryGetValue(Int32, out T)
Gets the value associated with a given key.
Declaration
public bool TryGetValue(int key, out T value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | key | The key of the value to get. |
T | value | When this method returns, contains the value associated with the specified key, if the key is found;
otherwise, the default value for the type of the |
Returns
Type | Description |
---|---|
Boolean | true if the dictionary contains an element with the specified key; otherwise, false. |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through the dictionary in ascending key order.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | An enumerator for the dictionary. |