sealed class Tinman.Core.Util.IdGenerator<T ref>

Helper class that creates a bijective mapping between objects and integer identifiers.

An integer identifier (greater than zero) is assigned to each distinct value that is added to the IdGenerator object. Identifier values of removed mappings are not reused, so identifier values are truly unique.

Public / Constructors


public constructor IdGenerator → (2)

equals opt : EqualsDelegate<T> = null

The equality comparer.

hashCode opt : HashCodeDelegate<T> = null

The hash code delegate.

Creates a new instance of IdGenerator.

Public / Methods


public method Clear → ()

Clears all object/identifier mappings.


public method IdToValue → (2)

identifier in : int32

The identifier.

defaultValue opt : T = default(T)

Value to return if no mapping exists.

returns → T

The mapped value.

Returns the object for the given identifier.


public method RemoveId → (1)

identifier in : int32

The identifier.

Removes the given mapping, if it exists.


public method RemoveValue → (1)

value in : T

The object.

Removes the given mapping, if it exists.


public method TryValueToId → (1)

value in : T

The object.

returns → int32

The identifier or 0 if no mapping exists.

Returns the identifier for the given object if a mapping exists.


public method ValueToId → (2)

value in : T

The object.

add opt : bool = true

Create a new mapping for value in, if necessary?

returns → int32

The identifier or 0 iff no mapping exists for value in and add opt is false.

Returns the identifier for the given object.

Public / Attributes


public attribute Count → (get)

value : int32

The number of mappings.

Returns the number of mapping.

The generated integer identifiers will be in the range [1..xref:api/Tinman.Core.Util.IdGenerator.adoc#Count-attrib-pub[.


public attribute Ids → (get)

value : IBagConst<int32>

The mapped identifiers.

Returns the mapped identifiers.


public attribute Values → (get)

value : IBagConst<T>

The mapped values.

Returns the mapped values.