Class mata::EnumAlphabet

class EnumAlphabet : public Alphabet

Enumerated alphabet using a set of integers as symbols maintaining a set of specified symbols.

EnumAlphabet is a version of direct (identity) alphabet (does not give names to symbols, their name is their integer value directly). However, unlike IntAlphabet, EnumAlphabet maintains an ordered set of symbols in the alphabet.

Therefore, calling member functions get_complement() and get_alphabet_symbols() makes sense in the context of EnumAlphabet and the functions give the expected results.

Example:

Alphabet alph{ EnumAlphabet{ 0, 4, 6, 8, 9 } };
CHECK(alph.translate_symb("6") == 6);
CHECK_THROWS(alph.translate_symb("5")); // Throws an exception about an unknown symbol.
CHECK(alph.get_complement({ utils::OrdVector<Symbol>{ 0, 6, 9 } }) == utils::OrdVector<Symbol>{ 4, 8 });

Public Functions

inline virtual utils::OrdVector<Symbol> get_alphabet_symbols() const override

Get a set of all symbols in the alphabet.

The result does not have to equal the list of symbols in the automaton using this alphabet.

inline virtual utils::OrdVector<Symbol> get_complement(const utils::OrdVector<Symbol> &symbols) const override

complement of a set of symbols wrt the alphabet

virtual std::string reverse_translate_symbol(Symbol symbol) const override

Translate internal symbol representation back to its original string name.

Throws an exception when the symbol is missing in the alphabet.

Parameters:

symbol[in] Symbol to translate.

Returns:

symbol original name.

inline void add_symbols_from(const mata::utils::OrdVector<Symbol> &symbols)

Expand alphabet by symbols from the passed symbols.

Adding a symbol name which already exists will throw an exception.

Parameters:

symbols[in] Vector of symbols to add.

inline void add_symbols_from(const EnumAlphabet &alphabet)

Expand alphabet by symbols from the passed alphabet.

Parameters:

symbols_to_add[in] Vector of symbols to add.

virtual Symbol translate_symb(const std::string &str) override

translates a string into a symbol

virtual Word translate_word(const WordName &word_name) const override

Translate sequence of symbol names to sequence of their respective values.

void add_new_symbol(const std::string &symbol)

Add new symbol to the alphabet with the value identical to its string representation.

Parameters:

symbol[in] User-space representation of the symbol.

Returns:

Result of the insertion as InsertionResult.

void add_new_symbol(Symbol symbol)

Add new symbol to the alphabet.

Parameters:
  • key[in] User-space representation of the symbol.

  • symbol[in] Number of the symbol to be used on transitions.

Returns:

Result of the insertion as InsertionResult.

inline Symbol get_next_value() const

Get the next value for a potential new symbol.

Returns:

Next Symbol value.

inline size_t get_number_of_symbols() const

Get the number of existing symbols, epsilon symbols excluded.

Returns:

The number of symbols.

inline virtual bool empty() const override

Checks whether the alphabet has any symbols.

void update_next_symbol_value(Symbol value)

Update next symbol value when appropriate.

When the newly inserted value is larger or equal to the current next symbol value, update the next symbol value to a value one larger than the new value.

Parameters:

value – The value of the newly added symbol.

size_t erase(const Symbol symbol)

Erase a symbol from the alphabet.

Returns:

Number of symbols erased (0 or 1).

inline void erase(utils::OrdVector<Symbol>::const_iterator pos)

Remove a symbol name value pair from the position pos from the alphabet.

Returns:

Iterator following the last removed element.

inline void erase(utils::OrdVector<Symbol>::const_iterator first, utils::OrdVector<Symbol>::const_iterator last)

Remove a symbol name value pair from the positions between first and last from the alphabet.

Returns:

Iterator following the last removed element.

inline Symbol operator[](const std::string &symb)

also translates strings to symbols

inline virtual bool is_equal(const Alphabet &other_alphabet) const

Check whether two alphabets are equal.

In general, two alphabets are equal if and only if they are of the same class instance.

Parameters:

other_alphabet – The other alphabet to compare with for equality.

Returns:

True if equal, false otherwise.

inline virtual bool is_equal(const Alphabet *const other_alphabet) const

Check whether two alphabets are equal.

In general, two alphabets are equal if and only if they are of the same class instance.

Parameters:

other_alphabet – The other alphabet to compare with for equality.

Returns:

True if equal, false otherwise.