-
Notifications
You must be signed in to change notification settings - Fork 13
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
Refactor types and names #299
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## devel #299 +/- ##
==========================================
+ Coverage 82.58% 82.88% +0.29%
==========================================
Files 51 51
Lines 10599 10526 -73
Branches 1063 1034 -29
==========================================
- Hits 8753 8724 -29
+ Misses 1443 1414 -29
+ Partials 403 388 -15
☔ View full report in Codecov by Sentry. |
d0590b7
to
d0b1e8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No major issues.
@@ -26,6 +26,8 @@ | |||
namespace Mata { | |||
|
|||
using Symbol = unsigned; | |||
using Word = std::vector<Symbol>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, you probably discussed this with Lukas, but are you sure it is good to introduce new types, after we aggresively removed lots of types? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did discuss it. The plan is that Word
and WordName
are to be the interface for working with alphabets. And therefore deserve a type of their own. The user will work with word names (a sequence of strings representing names of each symbol in a word), while Mata works internally with words (a sequence of Mata::Symbol
s). This is the place to discuss this idea with all of us, so feel free to give your opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thing having this one named is good, it appears on many places later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will keep it, at least until we see how well it works with refactored alphabets (coming soon to you Mata clone!).
include/mata/nfa/nfa.hh
Outdated
* @param[out] state_renaming Mapping of trimmed states to new states. | ||
* @return New @c Nfa instace from @c this with trimmed states. | ||
*/ | ||
Nfa trimmed(StateRenaming* state_renaming = nullptr) const { return Nfa{ *this }.trim(state_renaming); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this naming is confusing, having trim
and trimmed
will only confuse users, so I suggest to brainstorm some better name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that the operations that work in-place will usually have the name after the operation (usually a verb) and what it does to the instance the operation is called on. The operations returning a new instance will be named after the result, the new instance, which in this case is the trimmed NFA. Again, this is the idea. Let us discuss this here. trim()
and trimmed()
are the example of how it will look like. If we agree on using this pattern, all other functions will be renamed similarly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the idea, but the naming is probably not ideal. I though of copy_trimmed()
or clone_trimmed()
to show that a copy of the original automaton is made.
I think, we should more carefully unify naming convetion (mainly) for: 1. member operations (like nfa.trim()
, 2. non-member operation (like res = trim(nfa)
, 3. member operation returning clone/copy res = nfa.trim()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though of copy_trimmed() or clone_trimmed() to show that a copy of the original automaton is made.
I would prefer something like this, too, but others have to agree as well.
unify naming convetion
That is what I start doing here. This is an example of how it will look with trim()
, other function will follow. The naming convention (as of now, without your suggestion) should be:
trim()
trimmed()
trimmed()
However, a lot of the non-member operations should either disappear and be replaced with their member variants: determinize(nfa)
to nfa.determinized()
, etc. In some cases, especially for binary operations, both variants will exist: intersection(nfa, nfa2)
and nfa.intersection_with(nfa2)
plus the in-place variant may exist, too: concanation(nfa, nfa2)
, nfa.concatenate_with(nfa)
(in-place) and nfa.concatenated_with(nfa2)
.
But this approach still has its faults. We should discuss this further, think about possible problems, ... For further discussion, see #172 and #277 (comment) (and in other discussions in this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would refactor the trims first, we need to measure the speed and keep only the fastest, and then think about names. This verb /adjective naming system is not used consitently anyway, so it looks even weirder here.
Actually I confused it with revert, which I wanted to evaluate.
Here, lets just keep the in place trim and rename it then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can ad it in a separate pull request, lets merge this one quick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be done. I will remove trimmed()
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented few small things.
include/mata/nfa/nfa.hh
Outdated
* @param[out] state_renaming Mapping of trimmed states to new states. | ||
* @return New @c Nfa instace from @c this with trimmed states. | ||
*/ | ||
Nfa trimmed(StateRenaming* state_renaming = nullptr) const { return Nfa{ *this }.trim(state_renaming); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would refactor the trims first, we need to measure the speed and keep only the fastest, and then think about names. This verb /adjective naming system is not used consitently anyway, so it looks even weirder here.
Actually I confused it with revert, which I wanted to evaluate.
Here, lets just keep the in place trim and rename it then.
Nfa aut{20}; | ||
FILL_WITH_AUT_A(aut); | ||
aut.delta.add(0, EPSILON, 3); | ||
aut.delta.add(3, EPSILON, 3); | ||
aut.delta.add(3, EPSILON, 4); | ||
|
||
auto state_eps_trans{ aut.get_epsilon_transitions(0) }; | ||
auto state_eps_trans{ aut.delta.epsilon_symbol_posts(0) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_symbol remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this is not meant to be epsilon_symbol
and posts
, but epsilon
and sybol_posts
, as in, SymbolPost
for epsilon
from a given source. Therefore, the name should be kept as it is.
@@ -26,6 +26,8 @@ | |||
namespace Mata { | |||
|
|||
using Symbol = unsigned; | |||
using Word = std::vector<Symbol>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thing having this one named is good, it appears on many places later.
include/mata/nfa/nfa.hh
Outdated
* @param[out] state_renaming Mapping of trimmed states to new states. | ||
* @return New @c Nfa instace from @c this with trimmed states. | ||
*/ | ||
Nfa trimmed(StateRenaming* state_renaming = nullptr) const { return Nfa{ *this }.trim(state_renaming); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can ad it in a separate pull request, lets merge this one quick.
d0b1e8b
to
a539cc8
Compare
The changes from reviews that were not applied immediately will be applied in future PRs, namely in alphabet refactorization. |
This PR refactors some types, modifies some names, and in general resolves the majority of the issues from #292 and #283.
I suggest reviewing the code commit after commit in order to get an idea of what each change does and what is the impact of that change.
Further changes regarding transitions iterator and alphabet will come in their respective PRs as those are rather large modifications.