From 722a7eb202dc09c064c53e52cadf1cd0e36753c8 Mon Sep 17 00:00:00 2001 From: Maddie Busig Date: Tue, 6 May 2025 22:51:52 -0700 Subject: [PATCH] Move token marking identifier into token_t, remove marking rules This has the side effect that each token can only have one mark assigned to it. --- include/fractal.hpp | 33 ++------------------------------- src/fractal.cpp | 19 ++++--------------- src/main.cpp | 3 +-- 3 files changed, 7 insertions(+), 48 deletions(-) diff --git a/include/fractal.hpp b/include/fractal.hpp index 649809a..7659863 100644 --- a/include/fractal.hpp +++ b/include/fractal.hpp @@ -17,7 +17,6 @@ constexpr size_t g_max_tokens = 16; constexpr size_t g_max_groups = 8; constexpr size_t g_max_wgroups = 4; constexpr size_t g_max_branch_rules = 8; -constexpr size_t g_max_mark_rules = 4; constexpr size_t g_max_cgroup_tokens = 16; constexpr size_t g_max_wgroup_weights = 8; constexpr size_t g_max_match_groups = 8; @@ -27,7 +26,6 @@ using token_id_t = uint32_t; using group_id_t = uint32_t; using weighted_group_id_t = uint32_t; using branch_rule_id_t = uint32_t; -using mark_rule_id_t = uint32_t; enum class token_type_e { empty, @@ -38,6 +36,7 @@ enum class token_type_e { struct token_t { token_type_e m_type = token_type_e::empty; mtl::fixed m_value; + uint32_t m_mark; }; struct group_characteristic_t { @@ -92,11 +91,6 @@ struct branch_rule_t { } m_group; }; -struct mark_rule_t { - token_id_t m_match; - uint32_t m_tag; -}; - class ruleset_t { private: etl::vector m_tokens; @@ -104,7 +98,6 @@ private: etl::vector m_weighted_groups; etl::vector m_branch_rules; - etl::vector m_mark_rules; public: /** @@ -129,7 +122,7 @@ public: * * @exception @c mtl::length_error if the maximum number of tokens is reached */ - token_id_t add_token(token_type_e type, mtl::fixed value = 0); + token_id_t add_token(token_type_e type, mtl::fixed value = 0, uint32_t mark = 0); /** * @brief Checks if the maximum number of group characteristics has been reached @@ -225,29 +218,7 @@ public: */ branch_rule_id_t add_branch_rule_weighted(token_id_t match, weighted_group_id_t wgroup); - /** - * @brief Checks if the maximum number of mark rules has been reached - * - * @ret @c true if the number of mark rules in the ruleset equals @c g_max_mark_rules, @c false otherwise - */ - bool mark_rules_full() const { - return m_mark_rules.full(); - } - /** @brief Add a new marking rule to the ruleset - * - * Mark rules describe what tokens should have their positions output - * each generation. If a token has a match, its position and a tag is output. - * - * @param match Token to match and mark - * @param tag Marking identifier, does not need to be unique - * - * @ret @c mark_rule_id_t of the newly added mark rule - * - * @exception @c mtl::invalid_argument if an invalid token was supplied - * @exception @c mtl::length_error if the maximum number of mark rules was reached - */ - mark_rule_id_t add_mark_rule(token_id_t match, uint32_t tag); }; class generator_t { diff --git a/src/fractal.cpp b/src/fractal.cpp index 6f09809..ed8194d 100644 --- a/src/fractal.cpp +++ b/src/fractal.cpp @@ -22,12 +22,14 @@ mtl::mat<2, 2> create_rotation(mtl::fixed angle_cos) { namespace fractal { -token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value) { +// ---------- RULESET ---------- + +token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value, uint32_t mark) { if (m_tokens.full()) { throw mtl::length_error(); } - token_t tok { .m_type = type, .m_value = value }; + token_t tok { .m_type = type, .m_value = value, .m_mark = mark}; m_tokens.push_back(tok); return m_tokens.size() - 1; @@ -110,19 +112,6 @@ branch_rule_id_t ruleset_t::add_branch_rule_weighted(token_id_t match, weighted_ return m_branch_rules.size() - 1; } -mark_rule_id_t ruleset_t::add_mark_rule(token_id_t match, uint32_t tag) { - if (!valid_token(match)) { - throw mtl::invalid_argument(); - } - - mark_rule_t rule { - .m_match = match, - .m_tag = tag - }; - - m_mark_rules.push_back(rule); - return m_mark_rules.size() - 1; -} #if 0 token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) { diff --git a/src/main.cpp b/src/main.cpp index 7f528ec..f1c42fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ int main(void) { token_id_t branch = rules.add_token(token_type_e::empty); token_id_t petal = rules.add_token(token_type_e::empty); - token_id_t mark = rules.add_token(token_type_e::empty); + token_id_t mark = rules.add_token(token_type_e::empty, 0, 1); log::info << "Added tokens" << endl; @@ -52,7 +52,6 @@ int main(void) { rules.add_branch_rule(branch, branch_grp); rules.add_branch_rule(petal, petal_grp); - rules.add_mark_rule(mark, 1); log::info << "Added rules" << endl; log::info << "Finished configuring ruleset" << endl;