Class CanonicalAlphabet
Immutable and optimized representation of an alphabet with contiguous, ordered symbols.
Inherited Members
Namespace: Automata.Core
Assembly: Automata.Core.dll
Syntax
public class CanonicalAlphabet : IEquatable<CanonicalAlphabet>, IAlphabet
Remarks
A CanonicalAlphabet is defined by the following properties:
- Immutable: Structural and behavioral invariance, ensuring thread safety and predictable behavior.
- Performance: Optimized for fast, read-only operations with minimal memory overhead.
- Ordering: Symbols are sorted according to CanonicalStringComparer.
- Indexing: Symbols are associated with contiguous, ordered integer indices
[0..Count)
.
Constructors
| Edit this page View SourceCanonicalAlphabet(IEnumerable<string>)
Initializes a new instance of the CanonicalAlphabet class with the specified symbols.
Declaration
public CanonicalAlphabet(IEnumerable<string> symbols)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<string> | symbols | Symbols to initialize the alphabet with. |
Fields
| Edit this page View SourceStringToIndexMap
Declaration
public readonly FrozenDictionary<string, int> StringToIndexMap
Field Value
Type | Description |
---|---|
FrozenDictionary<string, int> |
Properties
| Edit this page View SourceCanonicalStringComparer
Canonical string comparer used by an alphabet, used to ensure canonical ordering of symbols, when required.
Declaration
public static StringComparer CanonicalStringComparer { get; }
Property Value
Type | Description |
---|---|
StringComparer |
Count
Number of symbols in the alphabet.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
Empty
An empty CanonicalAlphabet without any symbols.
Declaration
public static CanonicalAlphabet Empty { get; }
Property Value
Type | Description |
---|---|
CanonicalAlphabet |
this[int]
Symbol at the specified index.
Declaration
public string this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the symbol. |
Property Value
Type | Description |
---|---|
string | Symbol at the specified index. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the index is out of range. |
this[string]
Index of the specified symbol.
Declaration
public int this[string symbol] { get; }
Parameters
Type | Name | Description |
---|---|---|
string | symbol | Symbol to get the index of. |
Property Value
Type | Description |
---|---|
int | Index of the specified symbol, or InvalidSymbolIndex if the symbol does not exist. |
Symbols
Read-only collection of symbols in the alphabet.
Declaration
public IReadOnlyCollection<string> Symbols { get; }
Property Value
Type | Description |
---|---|
IReadOnlyCollection<string> |
Methods
| Edit this page View SourceContains(string)
Indicates whether the alphabet contains the specified symbol.
Declaration
public bool Contains(string symbol)
Parameters
Type | Name | Description |
---|---|---|
string | symbol | Symbol to check. |
Returns
Type | Description |
---|---|
bool | true
|
Equals(CanonicalAlphabet?)
Indicates whether the current alphabet is equal (identical) to another alphabet.
Declaration
public bool Equals(CanonicalAlphabet? other)
Parameters
Type | Name | Description |
---|---|---|
CanonicalAlphabet | other |
Returns
Type | Description |
---|---|
bool |
Equals(object?)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
| Edit this page View SourceGetHashCode()
Hash code for the current alphabet.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the alphabet. |
Overrides
| Edit this page View SourceToString()
String that represents the current alphabet, including its size.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of the alphabet. |
Overrides
| Edit this page View SourceToStringExpanded()
String with each symbol and its index, separated by a newline.
Declaration
public string ToStringExpanded()
Returns
Type | Description |
---|---|
string | A string with each symbol and its index, separated by a newline. |
Operators
| Edit this page View Sourceoperator ==(CanonicalAlphabet, CanonicalAlphabet)
Indicates whether two specified instances of CanonicalAlphabet are equal.
Declaration
public static bool operator ==(CanonicalAlphabet left, CanonicalAlphabet right)
Parameters
Type | Name | Description |
---|---|---|
CanonicalAlphabet | left | First alphabet to compare. |
CanonicalAlphabet | right | Second alphabet to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator !=(CanonicalAlphabet, CanonicalAlphabet)
Indicates whether two specified instances of CanonicalAlphabet are not equal.
Declaration
public static bool operator !=(CanonicalAlphabet left, CanonicalAlphabet right)
Parameters
Type | Name | Description |
---|---|---|
CanonicalAlphabet | left | First alphabet to compare. |
CanonicalAlphabet | right | Second alphabet to compare. |
Returns
Type | Description |
---|---|
bool | true
|