Commit 52e60aca authored by Philip Trettner's avatar Philip Trettner
Browse files

fixed permutations

parent 77ced122
...@@ -45,7 +45,6 @@ template <class Swap> ...@@ -45,7 +45,6 @@ template <class Swap>
void apply_permutation(std::vector<int> const& p, Swap&& s) void apply_permutation(std::vector<int> const& p, Swap&& s)
{ {
auto size = p.size(); auto size = p.size();
std::vector<int> cycle;
std::valarray<bool> visited(false, size); std::valarray<bool> visited(false, size);
for (auto pi = 0u; pi < size; ++pi) for (auto pi = 0u; pi < size; ++pi)
{ {
...@@ -54,7 +53,6 @@ void apply_permutation(std::vector<int> const& p, Swap&& s) ...@@ -54,7 +53,6 @@ void apply_permutation(std::vector<int> const& p, Swap&& s)
if (visited[i]) if (visited[i])
continue; continue;
cycle.clear();
visited[i] = true; visited[i] = true;
i = p[i]; i = p[i];
while (!visited[i]) while (!visited[i])
...@@ -62,15 +60,12 @@ void apply_permutation(std::vector<int> const& p, Swap&& s) ...@@ -62,15 +60,12 @@ void apply_permutation(std::vector<int> const& p, Swap&& s)
// mark // mark
visited[i] = true; visited[i] = true;
// add to cycle // swap
cycle.push_back(i); s(pi, i);
// advance // advance
i = p[i]; i = p[i];
} }
for (auto j = (int)cycle.size() - 1; j >= 0; --j)
s(pi, cycle[j]);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment