Implement add_weighted_group

This commit is contained in:
Madeline Busig 2025-04-29 06:14:14 -07:00
parent 20db4e7eea
commit 49f8d463ea
2 changed files with 25 additions and 1 deletions

View File

@ -168,7 +168,7 @@ public:
* @exception @c mtl::invalid_argument if no groups were supplied, or an invalid group was encountered * @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 * @exception @c mtl::length_error if the maximum number of groups is reached
*/ */
weighted_group_id_t add_weighted_group(const etl::ivector<group_id_t>& groups); weighted_group_id_t add_weighted_group(const etl::ivector<etl::pair<group_id_t, uint32_t>>& weights);
/** /**
* @brief Checks if the maximum number of branch rules has been reached * @brief Checks if the maximum number of branch rules has been reached

View File

@ -42,6 +42,30 @@ group_id_t ruleset_t::add_group_characteristic(const etl::ivector<token_id_t>& t
return m_group_characteristics.size() - 1; return m_group_characteristics.size() - 1;
} }
weighted_group_id_t ruleset_t::add_weighted_group(const etl::ivector<etl::pair<group_id_t, uint32_t>>& 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 #if 0
token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) { token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) {
log::debug << "Adding token with type " << (int)type << endl; log::debug << "Adding token with type " << (int)type << endl;