Class UniqueNameSet<T>
Generates a unique name for every value it is passed. Generated names are stored, but not associated with the object they originated from: generating a name for the same object twice will always result in two different unique names. The resulting name will never be null or empty.
Inherited Members
Namespace: Flame.Collections
Assembly: Flame.dll
Syntax
public sealed class UniqueNameSet<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to name. |
Constructors
| Edit this page View SourceUniqueNameSet(Func<T, string>, Func<T, int, string>)
Creates a unique name set from the given name-providing function, and a name-generating function that is used to resolve collisions.
Declaration
public UniqueNameSet(Func<T, string> getName, Func<T, int, string> generateName)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, string> | getName | A function that maps values to their preferred names. |
| Func<T, int, string> | generateName | A function that takes a value and an integer and combines them into a name. This function is called with increasingly large integers when a collision occurs, until a unique name is found. |
UniqueNameSet(Func<T, string>, Func<T, int, string>, UniqueNameSet<T>)
Creates a unique name set from the given name-providing function, and a name-generating function that is used to resolve collisions. This unique set's name pool is aliased with the given other unique name set.
Declaration
public UniqueNameSet(Func<T, string> getName, Func<T, int, string> generateName, UniqueNameSet<T> alias)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, string> | getName | A function that maps values to their preferred names. |
| Func<T, int, string> | generateName | A function that takes a value and an integer and combines them into a name. This function is called with increasingly large integers when a collision occurs, until a unique name is found. |
| UniqueNameSet<T> | alias | A unique name set with which this unique name set's generated names are aliased. |
UniqueNameSet(Func<T, string>, string)
Creates a unique name set from the given name-providing function, and a prefix that is used to resolve collisions.
Declaration
public UniqueNameSet(Func<T, string> getName, string prefix)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, string> | getName | A function that maps values to their preferred names. |
| string | prefix | A string prefix that is used to generate a unique name when a collision occurs. |
UniqueNameSet(Func<T, string>, string, UniqueNameSet<T>)
Creates a unique name set from the given name-providing function, and a prefix that is used to resolve collisions. This unique set's name pool is aliased with another unique name set.
Declaration
public UniqueNameSet(Func<T, string> getName, string prefix, UniqueNameSet<T> alias)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, string> | getName | A function that maps values to their preferred names. |
| string | prefix | A string prefix that is used to generate a unique name when a collision occurs. |
| UniqueNameSet<T> | alias | A unique name set with which this unique name set's generated names are aliased. |
Methods
| Edit this page View SourceGenerateName(T)
Generates a unique name for the given value.
Declaration
public string GenerateName(T element)
Parameters
| Type | Name | Description |
|---|---|---|
| T | element | The value to generate a name for. |
Returns
| Type | Description |
|---|---|
| string | A unique name. |
ReserveName(string)
Reserves a name, making sure it is never generated for any element.
Declaration
public bool ReserveName(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to reserve. |
Returns
| Type | Description |
|---|---|
| bool |
|