Class Alphabet
An alphabet associated with a finite state automaton.
Implements
Inherited Members
Namespace: Automata.Core
Assembly: Automata.Core.dll
Syntax
public class Alphabet : IEquatable<Alphabet>
Remarks
An Alphabet is a collection of symbols used by a finite state automaton. It can be extended with new symbols, but symbols cannot be removed. This enables multiple automata to share the same alphabet. Furthermore, automata never needs to deals with strings, but can use integer indices instead for all operations. Default behavior for operations that create new automata is to use the existing alphabet of the input automata. If a new alphabet is needed, an explicit creation of a new alphabet is typically required.
Constructors
| Edit this page View SourceAlphabet()
Initializes a new empty instance of the Alphabet class.
Declaration
public Alphabet()
Alphabet(Alphabet)
Initializes a new cloned instance of the Alphabet class from the specified alphabet.
Declaration
public Alphabet(Alphabet alphabet)
Parameters
Type | Name | Description |
---|---|---|
Alphabet | alphabet | Alphabet to initialize the alphabet with. |
Alphabet(IEnumerable<string>)
Initializes a new instance of the Alphabet class with the specified symbols.
Declaration
public Alphabet(IEnumerable<string> symbols)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<string> | symbols | Symbols to initialize the alphabet with. |
Alphabet(params string[])
Initializes a new instance of the Alphabet class with the specified symbols.
Symbols to initialize the alphabet with.Declaration
public Alphabet(params string[] symbols)
Parameters
Type | Name | Description |
---|---|---|
string[] | symbols |
Properties
| Edit this page View SourceCount
Number of symbols in the alphabet.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
this[int]
Symbol at the specified index.
Declaration
public string this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of the symbol to get. |
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 whose index to get. |
Property Value
Type | Description |
---|---|
int | Index of the specified symbol, or InvalidSymbolIndex if not found. |
SymbolIndices
Returns an enumerable collection of indices of the symbols in the alphabet. This is effectively the integers in range [0 .. Count).
Declaration
public IEnumerable<int> SymbolIndices { get; }
Property Value
Type | Description |
---|---|
IEnumerable<int> |
Symbols
Readonly collection of symbols in the alphabet.
Declaration
public IReadOnlyCollection<string> Symbols { get; }
Property Value
Type | Description |
---|---|
IReadOnlyCollection<string> |
Methods
| Edit this page View SourceAddAll(IEnumerable<string>)
Adds all the specified symbols to the alphabet that are not already present.
Declaration
public void AddAll(IEnumerable<string> symbols)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<string> | symbols | Symbols to add. |
Contains(int)
Indicates whether the alphabet contains the specified symbol as an integer.
Declaration
public bool Contains(int symbol)
Parameters
Type | Name | Description |
---|---|---|
int | symbol | Symbol index to locate in the alphabet. |
Returns
Type | Description |
---|---|
bool |
Contains(string)
Indicates whether the alphabet contains the specified symbol as a string.
Declaration
public bool Contains(string symbol)
Parameters
Type | Name | Description |
---|---|---|
string | symbol | Symbol string to locate in the alphabet. |
Returns
Type | Description |
---|---|
bool |
Equals(Alphabet?)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(Alphabet? other)
Parameters
Type | Name | Description |
---|---|---|
Alphabet | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
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()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
| Edit this page View SourceGetOrAdd(string)
Index of the specified symbol or adds it if it does not exist.
Declaration
public int GetOrAdd(string symbol)
Parameters
Type | Name | Description |
---|---|---|
string | symbol | Symbol to get or add. |
Returns
Type | Description |
---|---|
int | Index of the specified symbol. |
ToString()
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. |
TryGetIndex(string, out int)
Tries to get the index of the specified symbol.
Declaration
public bool TryGetIndex(string symbol, out int index)
Parameters
Type | Name | Description |
---|---|---|
string | symbol | Symbol whose index to get. |
int | index | When this method returns, contains the index of the specified symbol, if the symbol is found; otherwise, -1. |
Returns
Type | Description |
---|---|
bool |
UnionWith(Alphabet)
Add another alphabet to the current alphabet.
Declaration
public Dictionary<int, int> UnionWith(Alphabet other)
Parameters
Type | Name | Description |
---|---|---|
Alphabet | other | The other alphabet to merge into this. |
Returns
Type | Description |
---|---|
Dictionary<int, int> | A dictionary mapping indices from the other alphabet to the current alphabet. |
Operators
| Edit this page View Sourceoperator ==(Alphabet, Alphabet)
Declaration
public static bool operator ==(Alphabet left, Alphabet right)
Parameters
Type | Name | Description |
---|---|---|
Alphabet | left | |
Alphabet | right |
Returns
Type | Description |
---|---|
bool |
operator !=(Alphabet, Alphabet)
Declaration
public static bool operator !=(Alphabet left, Alphabet right)
Parameters
Type | Name | Description |
---|---|---|
Alphabet | left | |
Alphabet | right |
Returns
Type | Description |
---|---|
bool |