Implement add_weighted_group
This commit is contained in:
parent
20db4e7eea
commit
49f8d463ea
@ -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<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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
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
|
||||
token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) {
|
||||
log::debug << "Adding token with type " << (int)type << endl;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user