aboutsummaryrefslogtreecommitdiff
path: root/aberth/polygen.cpp
blob: 6df89dbcfddc2bf13c4e52e18da6f51b97434e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
    }
}