aboutsummaryrefslogtreecommitdiff
path: root/tests/performance/00_bitset2.sy
blob: b8b9e837aff79d3f5d3aba27f1558dcdd27d002d (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
int set(int a[], int pos, int d){
    const int bitcount = 30;
    int x[bitcount + 1] = {};

    x[0] = 1;
    x[1] = x[0] * 2;
    x[2] = x[1] * 2;
    x[3] = x[2] * 2;
    x[4] = x[3] * 2;
    x[5] = x[4] * 2;
    x[6] = x[5] * 2;
    x[7] = x[6] * 2;
    x[8] = x[7] * 2;
    x[9] = x[8] * 2;
    x[10] = x[9] * 2;
    
    int i = 10;
    while (i < bitcount){
        i = i + 1;
        x[i] = x[i - 1] * 2;
    }

    int v = 0;

    if (pos / bitcount >= 10000) return 0;
    
    if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){
        if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0)
            if (d == 1)
                v = x[pos % bitcount];
        
        if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1)
            if (d == 0)
                v = v - x[pos % bitcount];
    }

    a[pos / bitcount] = a[pos / bitcount] + v;
    return 0;
}

int seed[3] = {19971231, 19981013, 1000000000 + 7};
int staticvalue = 0;

int rand(){
    staticvalue = staticvalue * seed[0] + seed[1];
    staticvalue = staticvalue % seed[2];
    if (staticvalue < 0) staticvalue = seed[2] + staticvalue;
    return staticvalue;
}

int a[10000] = {};
int main(){
    
    int n = getint();
    staticvalue = getint();
    starttime();
    int x, y;
    while (n > 0){
        n = n - 1;
        x = rand() % 300000;
        y = rand() % 2;
        set(a, x, y);
    }
    stoptime();
    putarray(10000, a);
    return 0;
}