Skip to content
Snippets Groups Projects
Commit 0afa7a6b authored by Jan Trávníček's avatar Jan Trávníček
Browse files

moveable set and used in NFA determinisation algo

parent 200c7f02
No related branches found
No related tags found
No related merge requests found
...@@ -16,10 +16,10 @@ namespace automaton { ...@@ -16,10 +16,10 @@ namespace automaton {
   
namespace determinize { namespace determinize {
   
automaton::State createDFAState(const std::set<automaton::State>& nfaStates) { automaton::State createDFAState(std::set<automaton::State> nfaStates) {
std::set<label::Label> labelSet; std::set<label::Label> labelSet;
for(const automaton::State& state : nfaStates) { for(automaton::State state : std::make_moveable_set(nfaStates)) {
labelSet.insert(state.getName()); labelSet.insert(std::move(state.getName()));
} }
return automaton::State(label::Label(label::LabelSetLabel(std::move(labelSet)))); return automaton::State(label::Label(label::LabelSetLabel(std::move(labelSet))));
} }
......
...@@ -22,7 +22,7 @@ namespace determinize { ...@@ -22,7 +22,7 @@ namespace determinize {
* @param originalStates set of states from nondeterministic fsm which represents state of deterministic fsm * @param originalStates set of states from nondeterministic fsm which represents state of deterministic fsm
* @return state of deterministic fsm * @return state of deterministic fsm
*/ */
automaton::State createDFAState(const std::set<automaton::State>& nfaStates); automaton::State createDFAState(std::set<automaton::State> nfaStates);
   
/** /**
* Finds states from nondeterministic fsm to which at least one state from given set of states have transition * Finds states from nondeterministic fsm to which at least one state from given set of states have transition
......
...@@ -129,6 +129,26 @@ set_move_iterator<Iterator> make_set_move_iterator (Iterator it) { ...@@ -129,6 +129,26 @@ set_move_iterator<Iterator> make_set_move_iterator (Iterator it) {
return set_move_iterator<Iterator>(it); return set_move_iterator<Iterator>(it);
} }
   
template<class T>
class moveable_set {
set<T>& theSet;
public:
moveable_set(set<T>& param) : theSet(param) {}
set_move_iterator<typename set<T>::iterator> begin() {
return make_set_move_iterator(theSet.begin());
}
set_move_iterator<typename set<T>::iterator> end() {
return make_set_move_iterator(theSet.end());
}
};
template<class T>
moveable_set<T> make_moveable_set (std::set<T>& set) {
return moveable_set<T>(set);
}
} /* namespace std */ } /* namespace std */
   
#endif /* __SET_HPP_ */ #endif /* __SET_HPP_ */
......
...@@ -42,3 +42,42 @@ void SetTest::test2() { ...@@ -42,3 +42,42 @@ void SetTest::test2() {
CPPUNIT_ASSERT_EQUAL(firstMinusSecond.size(), 0ul); CPPUNIT_ASSERT_EQUAL(firstMinusSecond.size(), 0ul);
CPPUNIT_ASSERT_EQUAL(secondMinusFirst.size(), 2ul); CPPUNIT_ASSERT_EQUAL(secondMinusFirst.size(), 2ul);
} }
class Moveable {
int& moves;
int& copies;
public:
Moveable(int& moves, int& copies) : moves(moves), copies(copies) {
moves = 0;
copies = 0;
}
Moveable(const Moveable& src) : moves(src.moves), copies(src.copies) {
copies++;
}
Moveable(Moveable&& src) : moves(src.moves), copies(src.copies) {
moves++;
}
bool operator<(const Moveable&) const {
return false;
}
};
void SetTest::test3() {
int moves;
int copies;
std::set<Moveable> set = {Moveable(moves, copies)};
std::set<Moveable> set2;
for(Moveable moveable : std::make_moveable_set(set)) {
set2.insert(std::move(moveable));
}
CPPUNIT_ASSERT(copies == 0);
CPPUNIT_ASSERT(copies == 2);
}
...@@ -16,6 +16,7 @@ public: ...@@ -16,6 +16,7 @@ public:
   
void test1(); void test1();
void test2(); void test2();
void test3();
}; };
   
#endif // SET_TEST_H_ #endif // SET_TEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment