Class mata::OnTheFlyAlphabet

class OnTheFlyAlphabet : public Alphabet

An alphabet constructed ‘on the fly’.

Should be use anytime the automata have a specific names for the symbols.

Public Types

using InsertionResult = std::pair<StringToSymbolMap::const_iterator, bool>

Result of the insertion of a new symbol.

Public Functions

inline explicit OnTheFlyAlphabet(const std::vector<std::string> &symbol_names, Symbol init_symbol = 0)

Create alphabet from a list of symbol names.

Parameters:
  • symbol_names – Names for symbols on transitions.

  • init_symbol – Start of a sequence of values to use for new symbols.

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.

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.

void add_symbols_from(const std::vector<std::string> &symbol_names)

Expand alphabet by symbols from the passed symbol_names.

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

Parameters:

symbol_names[in] Vector of symbol names.

void add_symbols_from(const StringToSymbolMap &new_symbol_map)

Expand alphabet by symbols from the passed symbol_map.

The value of the already existing symbols will NOT be overwritten.

Parameters:

new_symbol_map[in] Map of strings to symbols.

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.

InsertionResult add_new_symbol(const std::string &key)

Add new symbol to the alphabet with the value of next_symbol_value.

Throws an exception when the adding fails.

Parameters:

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

Returns:

Result of the insertion as InsertionResult.

InsertionResult add_new_symbol(const std::string &key, Symbol value)

Add new symbol to the alphabet.

Throws an exception when the adding fails.

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

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

Returns:

Result of the insertion as InsertionResult.

inline InsertionResult try_add_new_symbol(const std::string &key, Symbol value)

Try to add symbol to the alphabet map.

Does not throw an exception when the adding fails.

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

  • value[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 const StringToSymbolMap &get_symbol_map() const

Get the symbol map used in the alphabet.

Returns:

Map mapping strings to symbols used internally in Mata.

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(Symbol symbol)

Remove a symbol name value pair specified by its symbol from the alphabet.

Warning

Complexity: O(n), where n is the number of symbols in the alphabet.

Returns:

Number of symbols removed (0 or 1).

size_t erase(const std::string &symbol_name)

Remove a symbol name value pair specified by its symbol_name from the alphabet.

Returns:

Number of symbols removed (0 or 1).

inline void erase(StringToSymbolMap::const_iterator pos)

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

inline void erase(StringToSymbolMap::const_iterator first, StringToSymbolMap::const_iterator last)

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

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.