Replace deallocation vector with std::vector and different merge algorithm

This commit is contained in:
Patrick Niklaus
2017-10-11 23:23:57 +00:00
committed by Patrick Niklaus
parent 69db219423
commit 9b87b8b7b1
5 changed files with 86 additions and 69 deletions
+20
View File
@@ -23,7 +23,15 @@ void inplacePermutation(RandomAccesIterator begin,
for (auto index : util::irange<IndexT>(0, size))
{
if (was_replaced[index])
{
continue;
}
if (old_to_new[index] == index)
{
was_replaced[index] = true;
continue;
}
// iterate over a cycle in the permutation
auto buffer = begin[index];
@@ -38,6 +46,18 @@ void inplacePermutation(RandomAccesIterator begin,
std::swap(buffer, begin[index]);
}
}
template <typename IndexT>
std::vector<IndexT> orderingToPermutation(const std::vector<IndexT> &ordering)
{
std::vector<std::uint32_t> permutation(ordering.size());
for (auto index : util::irange<std::uint32_t>(0, ordering.size()))
permutation[ordering[index]] = index;
return permutation;
}
}
}