68 template <
typename ValueType =
long unsigned int,
69 typename DecompositionValueType =
unsigned int>
87 typedef typename decomposition_type::size_type
size_type;
203 template <
typename ValueType,
typename DecompositionValueType>
218 template <
typename ValueType,
typename DecompositionValueType>
224 if (_alphabet.
size() < 2)
232 _ertable.reserve(_alphabet.
size());
233 _ertable.assign(_alphabet.
size(), std::vector<value_type>(smallestMass, _infty));
241 _witnessVector.resize(smallestMass);
244 size_type it_inc = secondMass % smallestMass, witness = 1;
252 _ertable[1][it_i] = mass;
255 _witnessVector[it_i] = std::make_pair(witness, counter);
258 if (it_i >= _ertable[1].size())
260 it_i -= _ertable[1].size();
265 _lcms[1] = secondMass * smallestMass / tmp_d;
266 _mass_in_lcms[1] = smallestMass / tmp_d;
278 _lcms[i] = currentMass * smallestMass / d;
279 _mass_in_lcms[i] = smallestMass / d;
282 if (currentMass >= _ertable[i - 1][currentMass % smallestMass])
284 _ertable[i] = _ertable[i - 1];
297 size_type p_inc = currentMass % smallestMass;
306 for (
size_type m = smallestMass; m > 0; --m)
311 if (p >= smallestMass)
315 if (n > prev_column[p])
322 _witnessVector[p] = std::make_pair(i, local_counter);
334 size_type cur = currentMass % smallestMass;
338 std::vector<decomposition_value_type> counters(smallestMass);
343 cur_column[j] = prev_column[j];
347 for (
size_type m = smallestMass / d; m > 1; m--)
354 if (cur_column[prev] + currentMass > prev_column[cur])
356 cur_column[cur] = prev_column[cur];
361 cur_column[cur] = cur_column[prev] + currentMass;
362 _witnessVector[cur] = std::make_pair(i, counters[cur]);
373 if (cur >= smallestMass)
389 if (cur_column[prev] + currentMass < cur_column[cur])
391 cur_column[cur] = cur_column[prev] + currentMass;
393 _witnessVector[cur] = std::make_pair(i, counters[cur]);
406 if (cur >= smallestMass)
416 template <
typename ValueType,
typename DecompositionValueType>
421 value_type residue = ertable_.back().at(mass % alphabet_.getWeight(0));
422 return residue != infty_ && mass >= residue;
425 template <
typename ValueType,
typename DecompositionValueType>
431 if (!this->exist(mass))
433 return decomposition;
436 decomposition.reserve(alphabet_.size());
437 decomposition.resize(alphabet_.size());
443 decomposition.at(0) = static_cast<decomposition_value_type>
444 ((mass - m) / alphabet_.getWeight(0));
448 size_type i = witness_vector_.at(r).first;
450 decomposition.at(i) += j;
451 if (m < j * alphabet_.getWeight(i))
455 m -= j * alphabet_.getWeight(i);
456 r = m % alphabet_.getWeight(0);
458 return decomposition;
461 template <
typename ValueType,
typename DecompositionValueType>
467 collectDecompositionsRecursively_(mass, alphabet_.size() - 1, decomposition, decompositionsStore);
468 return decompositionsStore;
471 template <
typename ValueType,
typename DecompositionValueType>
476 if (alphabetMassIndex == 0)
478 value_type numberOfMasses0 = mass / alphabet_.getWeight(0);
479 if (numberOfMasses0 * alphabet_.getWeight(0) == mass)
481 decomposition[0] = static_cast<decomposition_value_type>(numberOfMasses0);
482 decompositionsStore.push_back(decomposition);
489 const value_type lcm = lcms_[alphabetMassIndex];
490 const value_type mass_in_lcm = mass_in_lcms_[alphabetMassIndex];
492 value_type mass_mod_alphabet0 = mass % alphabet_.getWeight(0);
493 const value_type mass_mod_decrement = alphabet_.getWeight(alphabetMassIndex) % alphabet_.getWeight(0);
498 decomposition[alphabetMassIndex] = static_cast<decomposition_value_type>(i);
502 if (mass < i * alphabet_.getWeight(alphabetMassIndex))
508 value_type r = ertable_[alphabetMassIndex - 1][mass_mod_alphabet0];
513 for (
value_type m = mass - i * alphabet_.getWeight(alphabetMassIndex); m >= r; m -= lcm)
518 collectDecompositionsRecursively_(m, alphabetMassIndex - 1, decomposition, decompositionsStore);
519 decomposition[alphabetMassIndex] += mass_in_lcm;
529 if (mass_mod_alphabet0 < mass_mod_decrement)
531 mass_mod_alphabet0 += alphabet_.getWeight(0) - mass_mod_decrement;
535 mass_mod_alphabet0 -= mass_mod_decrement;
549 template <
typename ValueType,
typename DecompositionValueType>
551 DecompositionValueType>::getNumberOfDecompositions(
value_type mass)