/** * Arguments merging in case of univariate monomial is meaningful only when extending a zero-arguments * monomial to one argument. Therefore, this method will either throw or return a default-constructed monomial. * * @param[in] orig_args original arguments. * @param[in] new_args new arguments. * * @return a default-constructed instance of piranha::univariate_monomial. * * @throws std::invalid_argument if the size of \p new_args is different from 1 or the size of \p orig_args is not zero. * @throws unspecified any exception thrown by the default constructor of piranha::univariate_monomial. */ univariate_monomial merge_args(const symbol_set &orig_args, const symbol_set &new_args) const { piranha_assert(std::is_sorted(orig_args.begin(),orig_args.end())); piranha_assert(std::is_sorted(new_args.begin(),new_args.end())); if (unlikely(new_args.size() != 1u || orig_args.size())) { piranha_throw(std::invalid_argument,"invalid symbol set"); } piranha_assert(math::is_zero(m_value)); // The only valid possibility here is that a monomial with zero args is extended // to one arg. Default construction is ok. return univariate_monomial(); }
/// \brief Moves to a new state when the specified range of symbols are encountered inline void ndfa::builder::add_with_surrogates(const symbol_set& symbols) { // Get the state that should be moved to by this transition int nextState = m_NextState; m_NextState = -1; // Use a new state if no state has been explicitly set if (nextState == -1) { nextState = m_Ndfa->add_state(); } // If generate surrogates is turned on, and the symbol set ends outside the surrogate range if (m_GenerateSurrogates) { // Search to see if there are any surrogate ranges symbol_set surrogates; symbol_set nonSurrogates; // Look through the symbol set for (symbol_set::iterator syms = symbols.begin(); syms != symbols.end(); ++syms) { // Ignore empty ranges if (syms->lower() >= syms->upper()) continue; if (syms->upper() > 0x10000) { // Surrogate range if (syms->lower() <= 0xffff) { // Split range nonSurrogates |= range<int>(syms->lower(), 0x10000); surrogates |= range<int>(0x10000, syms->upper()); } else { // Just a surrogate range surrogates |= *syms; } } else { // Not a surrogate range nonSurrogates |= *syms; } } // See if there were any surrogate ranges if (!surrogates.empty()) { // Push before this surrogate push(); if (!nonSurrogates.empty()) { // Just add a transition on the non-surrogate range m_Ndfa->add_transition(m_CurrentState, nonSurrogates, nextState); } // Add a surrogate transition for each surrogate range for (symbol_set::iterator syms = surrogates.begin(); syms != surrogates.end(); ++syms) { add_surrogate_transition(*syms, m_CurrentState, nextState, m_Ndfa); } // Update the current state m_PreviousState = m_CurrentState; m_CurrentState = nextState; // Pop afterwards pop(); // Done return; } } // Add the transition for these symbols m_Ndfa->add_transition(m_CurrentState, symbols, nextState); m_PreviousState = m_CurrentState; m_CurrentState = nextState; }