Esempio n. 1
0
 Factors join(const Factors & lhs, const Factors & rhs) {
     Factors retval;
     retval.reserve(lhs.size() + rhs.size());
     retval.insert(std::end(retval), std::begin(lhs), std::end(lhs));
     retval.insert(std::end(retval), std::begin(rhs), std::end(rhs));
     return retval;
 }
Esempio n. 2
0
    PartialFactors toPartialFactors(const Factors & f) {
        PartialFactors retval;

        retval.first.resize(f.size());
        for (size_t i = 0; i < f.size(); ++i)
            retval.first[i] = i;
        retval.second = f;

        return retval;
    }
Esempio n. 3
0
 size_t toIndex(const Factors & space, const Factors & f) {
     size_t result = 0; size_t multiplier = 1;
     for (size_t i = 0; i < f.size(); ++i) {
         result += multiplier * f[i];
         multiplier *= space[i];
     }
     return result;
 }
Esempio n. 4
0
    void toFactors(const Factors & space, size_t id, Factors * out) {
        assert(out);

        auto & f = *out;

        for (size_t i = 0; i < space.size(); ++i) {
            f[i] = id % space[i];
            id /= space[i];
        }
    }
Esempio n. 5
0
 size_t toIndex(const Factors & space, const PartialFactors & f) {
     size_t result = 0; size_t multiplier = 1;
     for (size_t i = 0, j = 0; i < space.size(); ++i) {
         if (i == f.first[j]) {
             result += multiplier * f.second[j++];
             if (j == f.first.size()) break;
         }
         multiplier *= space[i];
     }
     return result;
 }
Esempio n. 6
0
 Factors toFactors(const Factors & space, size_t id) {
     Factors f(space.size());
     toFactors(space, id, &f);
     return f;
 }