39std::vector<Input_>
create_factor(
const std::size_t n,
const Input_*
const input, Code_*
const codes) {
41 std::unordered_map<Input_, Code_> mapping;
42 for (I<
decltype(n)> i = 0; i < n; ++i) {
43 const auto current = input[i];
44 const auto mIt = mapping.find(current);
45 if (mIt != mapping.end()) {
46 codes[i] = mIt->second;
48 Code_ alt = mapping.size();
49 mapping[current] = alt;
53 return std::vector<std::pair<Input_, Code_> >(mapping.begin(), mapping.end());
57 std::sort(unique.begin(), unique.end());
58 const auto nuniq = unique.size();
59 auto remapping = sanisizer::create<std::vector<Code_> >(nuniq);
60 auto output = sanisizer::create<std::vector<Input_> >(nuniq);
61 for (I<
decltype(nuniq)> u = 0; u < nuniq; ++u) {
62 remapping[unique[u].second] = u;
63 output[u] = unique[u].first;
67 for (I<
decltype(n)> i = 0; i < n; ++i) {
68 codes[i] = remapping[codes[i]];
std::vector< Input_ > create_factor(const std::size_t n, const Input_ *const input, Code_ *const codes)
Definition create_factor.hpp:39