diff --git a/lib/dummy.cpp b/lib/dummy.cpp deleted file mode 100644 index 738e51c..0000000 --- a/lib/dummy.cpp +++ /dev/null @@ -1,2 +0,0 @@ -static int x=x; - diff --git a/lib/mealy.hpp b/lib/mealy.hpp index 4f17dfb..df3385c 100644 --- a/lib/mealy.hpp +++ b/lib/mealy.hpp @@ -1,9 +1,15 @@ #pragma once +#include "phantom.hpp" + #include #include #include +using state = phantom; +using input = phantom; +using output = phantom; + /* * Structure used for reading mealy files from dot files. * Everything is indexed by size_t's, so that we can index vectors @@ -13,13 +19,13 @@ */ struct Mealy { struct edge { - size_t to = -1; - size_t output = -1; + state to = -1; + output output = -1; }; - std::map nodes_indices; - std::map input_indices; - std::map output_indices; + std::map nodes_indices; + std::map input_indices; + std::map output_indices; // state -> input -> (output, state) std::vector> graph; @@ -31,19 +37,19 @@ struct Mealy { }; inline auto is_complete(const Mealy & m){ - for(int n = 0; n < m.graph_size; ++n){ - if(m.graph[n].size() != m.input_size) return false; - for(auto && e : m.graph[n]) if(e.to == -1 || e.output == -1) return false; + for(state n = 0; n < m.graph_size; ++n){ + if(m.graph[n.base()].size() != m.input_size) return false; + for(auto && e : m.graph[n.base()]) if(e.to == -1 || e.output == -1) return false; } return true; } -inline auto apply(Mealy const & m, size_t state, size_t input){ - return m.graph[state][input]; +inline auto apply(Mealy const & m, state state, input input){ + return m.graph[state.base()][input.base()]; } template -auto apply(Mealy const & m, size_t state, Iterator b, Iterator e){ +auto apply(Mealy const & m, state state, Iterator b, Iterator e){ Mealy::edge ret; while(b != e){ ret = apply(m, state, *b++); diff --git a/lib/phantom.hpp b/lib/phantom.hpp index e03b80f..07687b5 100644 --- a/lib/phantom.hpp +++ b/lib/phantom.hpp @@ -5,7 +5,13 @@ template struct phantom : boost::operators>, boost::shiftable> { + phantom() = default; phantom(Base y) : x(y) {} + phantom(phantom const &) = default; + phantom& operator=(phantom const &) = default; + phantom(phantom &&) = default; + phantom& operator=(phantom &&) = default; + explicit operator Base() const { return x; } Base base() const { return x; } @@ -41,4 +47,3 @@ std::ostream & operator<<(std::ostream & out, phantom p){ return out << p. template std::istream & operator>>(std::istream & in, phantom & p){ return in >> p.x; } - diff --git a/lib/read_mealy_from_dot.cpp b/lib/read_mealy_from_dot.cpp index 9e33a14..84b27ac 100644 --- a/lib/read_mealy_from_dot.cpp +++ b/lib/read_mealy_from_dot.cpp @@ -55,9 +55,9 @@ Mealy read_mealy_from_dot(istream& in, int verbose){ // add edge m.graph.resize(m.graph_size); - auto & v = m.graph[m.nodes_indices[lh]]; + auto & v = m.graph[m.nodes_indices[lh].base()]; v.resize(m.input_size); - v[m.input_indices[input]] = {m.nodes_indices[rh], m.output_indices[output]}; + v[m.input_indices[input].base()] = {m.nodes_indices[rh], m.output_indices[output]}; } if(verbose >= 1){ diff --git a/src/main.cpp b/src/main.cpp index ded2abb..677f4a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,9 +19,9 @@ struct splijtboom { iota(begin(states), end(states), 0); } - vector states; + vector states; vector children; - vector seperator; + vector seperator; int mark = 0; }; @@ -95,9 +95,9 @@ int main(int argc, char *argv[]){ } // First try to split on output - for(size_t symbol = 0; symbol < P; ++symbol){ - auto new_blocks = part.refine(block, [symbol, &g](size_t state){ - return apply(g, state, symbol).output; + for(input symbol = 0; symbol < P; ++symbol){ + auto new_blocks = part.refine(block, [symbol, &g](state state){ + return apply(g, state, symbol).output.base(); }, Q); if(elems_in(new_blocks) == 1){ @@ -129,14 +129,14 @@ int main(int argc, char *argv[]){ } // Then try to split on state - for(size_t symbol = 0; symbol < P; ++symbol){ + for(input symbol = 0; symbol < P; ++symbol){ vector successor_states(N, false); for(auto && state : *block){ - successor_states[g.graph[state][symbol].to] = true; + successor_states[apply(g, state, symbol).to.base()] = true; } - auto & oboom = lca(root, [&successor_states](size_t state) -> bool{ - return successor_states[state]; + auto & oboom = lca(root, [&successor_states](state state) -> bool{ + return successor_states[state.base()]; }); if(oboom.children.empty()){ @@ -163,7 +163,7 @@ int main(int argc, char *argv[]){ copy(begin(oboom.seperator), end(oboom.seperator), it); auto new_blocks = part.refine(block, [&boom, &g](size_t state){ - return apply(g, state, begin(boom.seperator), end(boom.seperator)).output; + return apply(g, state, begin(boom.seperator), end(boom.seperator)).output.base(); }, Q); if(elems_in(new_blocks) == 1){