aboutsummaryrefslogtreecommitdiff
path: root/aberth/polygen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'aberth/polygen.cpp')
-rw-r--r--aberth/polygen.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/aberth/polygen.cpp b/aberth/polygen.cpp
new file mode 100644
index 0000000..6df89db
--- /dev/null
+++ b/aberth/polygen.cpp
@@ -0,0 +1,43 @@
+#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;
+ }
+
+ vector<Job> genJobs(int targetJobs) {
+ int njobs = min(1 << N, ceil2(targetJobs));
+ int jobsize = (1 << N) / njobs;
+
+ vector<Job> jobs(njobs);
+ for (int i = 0; i < njobs; i++) {
+ jobs[i].init = atIndex(i * jobsize);
+ jobs[i].numItems = jobsize;
+ }
+
+ return jobs;
+ }
+}