IdGenerator

Description

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

Id​Generator


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

Clear


public method Clear → ()

Clears all object/identifier mappings.

Id​To​Value


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.

Remove​Id


public method RemoveId → (1)

identifier in : int32

The identifier.

Removes the given mapping, if it exists.

Remove​Value


public method RemoveValue → (1)

value in : T

The object.

Removes the given mapping, if it exists.

Try​Value​To​Id


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.

Value​To​Id


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

Count


public attribute Count → (get)

value : int32

[>=0]
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[.

Ids


public attribute Ids → (get)

value : IBagConst<int32>

[not-null]
The mapped identifiers.

Returns the mapped identifiers.

Values


public attribute Values → (get)

value : IBagConst<T>

[not-null]
The mapped values.

Returns the mapped values.