| 16 | /** Compute the remainder of a polynomial division of val by mod, putting the result in mod. */ |
| 17 | template<typename F> |
| 18 | void PolyMod(const std::vector<typename F::Elem>& mod, std::vector<typename F::Elem>& val, const F& field) { |
| 19 | size_t modsize = mod.size(); |
| 20 | CHECK_SAFE(modsize > 0 && mod.back() == 1); |
| 21 | if (val.size() < modsize) return; |
| 22 | CHECK_SAFE(val.back() != 0); |
| 23 | while (val.size() >= modsize) { |
| 24 | auto term = val.back(); |
| 25 | val.pop_back(); |
| 26 | if (term != 0) { |
| 27 | typename F::Multiplier mul(field, term); |
| 28 | for (size_t x = 0; x < mod.size() - 1; ++x) { |
| 29 | val[val.size() - modsize + 1 + x] ^= mul(mod[x]); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | while (val.size() > 0 && val.back() == 0) val.pop_back(); |
| 34 | } |
| 35 | |
| 36 | /** Compute the quotient of a polynomial division of val by mod, putting the quotient in div and the remainder in val. */ |
| 37 | template<typename F> |