#include #include "polygen.h" #include "util.h" using namespace std; namespace PolyGen::Derbyshire { // Returns whether we just looped around bool next(Poly &poly) { for (int i = 1; i < (int)poly.size(); i++) { if (poly[i] == -1) { poly[i] = 1; return false; } poly[i] = -1; } return true; } Poly atIndex(int index) { Poly poly; poly[0] = 1; for (int i = 1; i <= N; i++) { poly[i] = index & 1 ? 1 : -1; index >>= 1; } assert(index == 0); return poly; } int numPolys() { return 1 << N; } } namespace PolyGen::Christensen { // Returns whether we just looped around bool next(Poly &poly) { for (int i = 0; i < (int)poly.size(); i++) { if (poly[i] < kCoeffBound) { poly[i]++; return false; } poly[i] = -kCoeffBound; } return true; } Poly atIndex(int index) { Poly poly; for (int i = 0; i < (int)poly.size(); i++) { poly[i] = index % (2 * kCoeffBound + 1) - kCoeffBound; index /= 2 * kCoeffBound + 1; } assert(index == 0); return poly; } int numPolys() { return ipow(2 * kCoeffBound + 1, N + 1); } } namespace PolyGen { vector genJobs(int targetJobs) { int njobs = min(numPolys(), ceil2(targetJobs)); int jobsize = numPolys() / njobs; vector jobs(njobs); for (int i = 0; i < njobs; i++) { jobs[i].init = atIndex(i * jobsize); jobs[i].numItems = jobsize; } return jobs; } }