Skip to content

Commit c8c1e28

Browse files
committed
Remove unnecessary find() in q_prime
1 parent 2a798eb commit c8c1e28

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/pdaaal/engine/PAutomaton.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,9 @@ namespace pdaaal {
194194
for (auto &state : pda_states) {
195195
for (auto &rule : state._rules) {
196196
if (rule._operation == PDA::PUSH) {
197-
auto pair = std::make_pair(rule._to, rule._op_label);
198-
if (q_prime.find(pair) == q_prime.end()) {
199-
auto new_state = this->add_state(false, false);
200-
q_prime.emplace(pair, new_state);
197+
auto res = q_prime.emplace(std::make_pair(rule._to, rule._op_label), this->next_state_id());
198+
if (res.second) {
199+
this->add_state(false, false);
201200
}
202201
}
203202
}
@@ -333,7 +332,7 @@ namespace pdaaal {
333332
}
334333

335334
size_t PAutomaton::add_state(bool initial, bool accepting) {
336-
auto id = _states.size();
335+
auto id = next_state_id();
337336
_states.emplace_back(std::make_unique<state_t>(accepting, id));
338337
if (accepting) {
339338
_accepting.push_back(_states.back().get());
@@ -343,6 +342,9 @@ namespace pdaaal {
343342
}
344343
return id;
345344
}
345+
size_t PAutomaton::next_state_id() const {
346+
return _states.size();
347+
}
346348

347349
void PAutomaton::add_epsilon_edge(size_t from, size_t to, const trace_t *trace) {
348350
auto &edges = _states[from]->_edges;

src/pdaaal/engine/PAutomaton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ namespace pdaaal {
243243
[[nodiscard]] size_t number_of_labels() const { return _pda.number_of_labels(); }
244244

245245
size_t add_state(bool initial, bool accepting);
246+
size_t next_state_id() const;
246247

247248
void add_epsilon_edge(size_t from, size_t to, const trace_t *trace);
248249

0 commit comments

Comments
 (0)