Class IndexedSet<T>
A bidirectional mapping of unique elements to non-negative indexes.
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Collections
Assembly: Microsoft.ML.Probabilistic.Learners.dll
Syntax
[Serializable]
public class IndexedSet<T>
Type Parameters
Name | Description |
---|---|
T | The type of an element. |
Constructors
IndexedSet()
Initializes a new instance of the IndexedSet<T> class.
Declaration
public IndexedSet()
IndexedSet(IReader)
Initializes a new instance of the IndexedSet<T> class from a reader of a binary stream.
Declaration
public IndexedSet(IReader reader)
Parameters
Type | Name | Description |
---|---|---|
IReader | reader | The reader to load the indexed set from. |
IndexedSet(IEnumerable<T>)
Initializes a new instance of the IndexedSet<T> class.
Declaration
public IndexedSet(IEnumerable<T> elements)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | elements | A collection of elements. |
Properties
Count
Gets the number of elements in the indexed set.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Elements
Gets all elements in the indexed set.
Declaration
public IEnumerable<T> Elements { get; }
Property Value
Type | Description |
---|---|
IEnumerable<T> |
Indexes
Gets the indexes of all elements in the indexed set.
Declaration
public IEnumerable<int> Indexes { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Int32> |
Methods
Add(T, Boolean)
Adds a new element to the indexed set.
Declaration
public int Add(T element, bool throwIfPresent = true)
Parameters
Type | Name | Description |
---|---|---|
T | element | The element to add. |
Boolean | throwIfPresent | If true, an exception is throw when adding an element that is already present in the indexed set. Defaults to true. |
Returns
Type | Description |
---|---|
Int32 | The index of the added element. |
Clear()
Removes all elements from the indexed set.
Declaration
public void Clear()
Contains(T)
Returns true if the specified element is contained in the indexed set and false otherwise.
Declaration
public bool Contains(T element)
Parameters
Type | Name | Description |
---|---|---|
T | element | The element. |
Returns
Type | Description |
---|---|
Boolean | True if the specified element is contained in the indexed set and false otherwise. |
GetElementByIndex(Int32)
Gets an element for a specified index.
Declaration
public T GetElementByIndex(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to get the element for. |
Returns
Type | Description |
---|---|
T | The element. |
SaveForwardCompatible(IWriter)
Saves the elements of the indexed set to a binary writer.
Declaration
public void SaveForwardCompatible(IWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IWriter | writer | The writer to save the elements of the indexed set to. |
TryGetIndex(T, out Int32)
Gets the index for a specified element.
Declaration
public bool TryGetIndex(T element, out int index)
Parameters
Type | Name | Description |
---|---|---|
T | element | The element to get the index for. |
Int32 | index | The index for the specified element, if present in the set. |
Returns
Type | Description |
---|---|
Boolean | True if |