Skip to content

Commit

Permalink
feat(nft): Allow adding NFT transition from/to nonexistent states
Browse files Browse the repository at this point in the history
  • Loading branch information
Adda0 committed Dec 2, 2024
1 parent 5686596 commit ee9056a
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/nft/nft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,35 +312,32 @@ State Nft::add_state_with_level(const State state, const Level level) {
}

State Nft::insert_word(const State source, const Word &word, const State target) {
assert(0 < num_of_levels);
const size_t num_of_states_orig{ num_of_states() };
assert(source < num_of_states_orig);
assert(target < num_of_states_orig);
assert(levels[source] == levels[target]);
// Ensure both states exist in the NFT.
add_state(std::max(source, target));
if (levels[source] != levels[target]) {
throw std::invalid_argument{ "Inserting word between source and target states with different levels." };
}

const State first_new_state = num_of_states_orig;
const State word_tgt = Nfa::insert_word(source, word, target);
const State first_new_state = num_of_states();
const State word_target = Nfa::insert_word(source, word, target);
const size_t num_of_states_after = num_of_states();
const Level src_lvl = levels[source];
const Level source_level = levels[source];

Level lvl = (num_of_levels == 1 ) ? src_lvl : (src_lvl + 1) % static_cast<Level>(num_of_levels);
State state{ first_new_state };
for (; state < num_of_states_after; state++, lvl = (lvl + 1) % static_cast<Level>(num_of_levels)){
add_state_with_level(state, lvl);
}
Level lvl = (num_of_levels == 1) ? source_level : (source_level + 1) % static_cast<Level>(num_of_levels);
for (State state{ first_new_state }; state < num_of_states_after;
++state, lvl = (lvl + 1) % static_cast<Level>(num_of_levels)) { add_state_with_level(state, lvl); }

assert(levels[word_tgt] == 0 || levels[num_of_states_after - 1] < levels[word_tgt]);
assert(levels[word_target] == 0 || levels[num_of_states_after - 1] < levels[word_target]);

return word_tgt;
return word_target;
}

State Nft::insert_word(const State source, const Word& word) {
assert(source < levels.size());
if (num_of_states() <= source) { add_state(source); }
return insert_word(source, word, add_state_with_level(levels[source]));
}

State Nft::insert_word_by_parts(const State source, const std::vector<Word> &word_parts_on_levels, const State target) {
assert(0 < num_of_levels);
assert(word_parts_on_levels.size() == num_of_levels);
assert(source < num_of_states());
assert(target < num_of_states());
Expand Down

0 comments on commit ee9056a

Please sign in to comment.