Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move functions between Delta, Nfa, and mata::nfa #329

Merged
merged 23 commits into from
Sep 18, 2023
Merged

Move functions between Delta, Nfa, and mata::nfa #329

merged 23 commits into from
Sep 18, 2023

Conversation

Adda0
Copy link
Collaborator

@Adda0 Adda0 commented Sep 11, 2023

This PR reorganizes some functions between classes Delta, Nfa, and mata::nfa namespace.

Namely, the PR does the following:

  • moves functions having to do something with transitions and labels on transitions to Delta.
  • moves functions from mata::nfa which are in-place operations or constant checks to Nfa.
  • renames Nfa::size() to Nfa::num_of_states() to prevent further confusions about the meaning of aut.size().
  • Optimizes slightly a few code lines, mainly to prevent creating unnecessary temporary copies of class instances.

@Adda0 Adda0 force-pushed the move_to_delta branch 3 times, most recently from 1a1a054 to 8ef35fb Compare September 12, 2023 07:31
@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Patch coverage: 64.50% and project coverage change: +0.18% 🎉

Comparison is base (d1f1bb9) 72.74% compared to head (f679a26) 72.93%.
Report is 5 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #329      +/-   ##
==========================================
+ Coverage   72.74%   72.93%   +0.18%     
==========================================
  Files          33       33              
  Lines        4146     4134      -12     
  Branches      953      952       -1     
==========================================
- Hits         3016     3015       -1     
+ Misses        755      740      -15     
- Partials      375      379       +4     
Files Changed Coverage Δ
include/mata/nfa/plumbing.hh 94.44% <ø> (-0.30%) ⬇️
src/re2parser.cc 38.07% <ø> (ø)
src/strings/nfa-noodlification.cc 71.49% <20.00%> (ø)
src/strings/nfa-strings.cc 85.56% <50.00%> (ø)
src/nfa/delta.cc 82.78% <52.38%> (-6.47%) ⬇️
src/nfa/operations.cc 63.61% <63.75%> (-1.29%) ⬇️
include/mata/nfa/delta.hh 90.54% <80.00%> (+4.23%) ⬆️
src/nfa/concatenation.cc 92.06% <80.00%> (ø)
src/nfa/nfa.cc 80.00% <92.85%> (+9.96%) ⬆️
include/mata/nfa/nfa.hh 100.00% <100.00%> (ø)
... and 5 more

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Adda0 Adda0 marked this pull request as ready for review September 12, 2023 07:41
@@ -345,9 +346,16 @@ public:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, defragment above needs some comment

@@ -138,7 +133,7 @@ public:
*/
void unify_final();

bool is_state(const State &state_to_check) const { return state_to_check < size(); }
bool is_state(const State &state_to_check) const { return state_to_check < num_of_states(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is a method of delta, then the name is not good, because delta alone does not decide about whether a number is state or not. Maybe contains_state, has_state, ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three options (the original is_state() in the code, contains_state() and has_state()) sound good to me. Anyone else any preferences?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or uses_state

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is maybe even better. It clearly explains that the notion of is a state has no meaning for delta, and that this function instead checks whether the state is a source or a target for any transition. I would however rename it to used(State state) or used_state(State state), or, ideally, is_state_used(State state). What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a method uses_state(State state) to Delta.

include/mata/nfa/nfa.hh Outdated Show resolved Hide resolved
* @param[in] sink_state The state into which new transitions are added.
* @return True if some new transition was added to the NFA.
*/
bool make_complete(const Alphabet& alphabet, State sink_state);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just complete? the make anyway looks like making a new automaton

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have complete() as the operation and is_complete() as the check for completeness.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone else any opinions?

@@ -402,51 +442,6 @@ Nfa intersection(const Nfa& lhs, const Nfa& rhs,
Nfa concatenate(const Nfa& lhs, const Nfa& rhs, bool use_epsilon = false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concatenation, this creates a new nfa, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We can rename it to concatenation(). Anyone else any opinions on this?

* @return True if the language is empty, false otherwise.
*/
bool is_lang_empty(const Nfa& aut, Run* cex = nullptr);

Nfa uni(const Nfa &lhs, const Nfa &rhs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the annoyance this generates is really high

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nfa_union(), as for set_union() in OrdVector?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lang_union !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that lang_union() might be even better than nfa_union(), if we are to have some prefix to union, that is.

@@ -509,14 +504,6 @@ Nfa determinize(const Nfa& aut, std::unordered_map<StateSet, State> *subset_map
Nfa reduce(const Nfa &aut, StateRenaming *state_renaming = nullptr,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like in-place thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rename it to reduction() or reduced(). Anyone else any opinions on this?

}
return transitions_to_state;
}

void Delta::add(State source, Symbol symbol, State target) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do wa want insert everywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there is a remove() below it, too. Do we want to rename to insert() and erase() everywhere?

symbols.insert(symbol_post.symbol);
}
}
//TODO: is it necessary to return ordered vector? Would the number predicate suffice?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to this TODO, maybe we want to refactor?

@@ -167,25 +166,27 @@ cdef extern from "mata/nfa/nfa.hh" namespace "mata::nfa":
StateSet get_terminating_states()
void remove_epsilon(Symbol) except +
Copy link
Collaborator Author

@Adda0 Adda0 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a suggestion to rename remove_epsilon() to epsilon_removal() or epsilon_removed(), or epsilon_free(). Opinions?

@Adda0
Copy link
Collaborator Author

Adda0 commented Sep 18, 2023

MacOS performance tests fail on a completely unrelated issue about missing performance test data. I will ignore the fail for now. Let us see whether it fixes itself over time.

@Adda0 Adda0 merged commit 7a521f2 into devel Sep 18, 2023
18 of 20 checks passed
@Adda0 Adda0 deleted the move_to_delta branch September 18, 2023 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants