diff --git a/include/fractal.hpp b/include/fractal.hpp index 05da93d..db0c1fd 100644 --- a/include/fractal.hpp +++ b/include/fractal.hpp @@ -168,7 +168,7 @@ public: * @exception @c mtl::invalid_argument if no groups were supplied, or an invalid group was encountered * @exception @c mtl::length_error if the maximum number of groups is reached */ - weighted_group_id_t add_weighted_group(const etl::ivector& groups); + weighted_group_id_t add_weighted_group(const etl::ivector>& weights); /** * @brief Checks if the maximum number of branch rules has been reached diff --git a/src/fractal.cpp b/src/fractal.cpp index b51b740..f61e44a 100644 --- a/src/fractal.cpp +++ b/src/fractal.cpp @@ -42,6 +42,30 @@ group_id_t ruleset_t::add_group_characteristic(const etl::ivector& t return m_group_characteristics.size() - 1; } +weighted_group_id_t ruleset_t::add_weighted_group(const etl::ivector>& weights) { + if (m_weighted_groups.full()) { + throw mtl::length_error(); + } + if (weights.size() > g_max_wgroup_weights) { + throw mtl::length_error(); + } + + m_weighted_groups.push_back(weighted_group_t()); + weighted_group_t& wgroup = m_weighted_groups.back(); + + for (const auto& weight : weights) { + if (!valid_group_characteristic(weight.first)) { + throw mtl::invalid_argument(); + } + + wgroup.m_groups.push_back(weight.first); + wgroup.m_weights.push_back(weight.second); + wgroup.m_weight_total += weight.second; + } + + return m_weighted_groups.size() - 1; +} + #if 0 token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) { log::debug << "Adding token with type " << (int)type << endl;