1 #define PERL_NO_GET_CONTEXT
13 bit* bit_create(IV len) {
15 croak("Length less than 1");
22 Newxz(ret->t, len, IV);
26 void bit_free(bit *b) {
31 IV bit_query(bit *b, IV idx) {
32 if(idx > b->n || idx < 1){
33 croak("Index not in range [1," IVdf "]", b->n);
38 ret += b->t[idx], idx -= idx & -idx;
42 void bit_update(bit *b, IV idx, IV value) {
43 if(idx > b->n || idx < 1){
44 croak("Index not in range [1," IVdf "]", b->n);
48 b->t[idx] += value, idx += idx & -idx;
51 void bit_clear(bit *b) {
60 bit2d* bit2d_create(IV n, IV m) {
62 croak("A dimension is less than 1");
70 Newxz(ret->t, n * m, IV);
74 void bit2d_free(bit2d *b) {
79 IV bit2d_query(bit2d *b, IV i1, IV i2) {
80 if(i1 > b->n || i1 < 1) {
81 croak("Index 1 not in range [1," IVdf "]", b->n);
84 if(i2 > b->m || i2 < 1) {
85 croak("Index 2 not in range [1," IVdf "]", b->m);
92 ret += b->t[i1 * b->m + i2], i2 -= i2 & -i2;
98 void bit2d_update(bit2d *b, IV i1, IV i2, IV value) {
99 if(i1 > b->n || i1 < 1) {
100 croak("Index 1 not in range [1," IVdf "]", b->n);
103 if(i2 > b->m || i2 < 1) {
104 croak("Index 2 not in range [1," IVdf "]", b->m);
111 b->t[i1 * b->m + i2] += value, i2 += i2 & -i2;
116 void bit2d_clear(bit2d *b) {
117 Zero(b->t, b->n * b->m, IV);
120 typedef bit *Algorithm__BIT__XS;
121 typedef bit2d *Algorithm__BIT2D__XS;
123 MODULE = Algorithm::BIT::XS PACKAGE = Algorithm::BIT::XS PREFIX = bit_
127 Algorithm::BIT::XS bit_create(IV len);
129 void bit_free(Algorithm::BIT::XS b);
133 IV bit_query(Algorithm::BIT::XS b, IV idx);
135 void bit_update(Algorithm::BIT::XS b, IV idx, IV value);
137 void bit_clear(Algorithm::BIT::XS b);
139 MODULE = Algorithm::BIT::XS PACKAGE = Algorithm::BIT2D::XS PREFIX = bit2d_
143 Algorithm::BIT2D::XS bit2d_create(IV n, IV m);
145 void bit2d_free(Algorithm::BIT2D::XS b);
149 IV bit2d_query(Algorithm::BIT2D::XS b, IV i1, IV i2);
151 void bit2d_update(Algorithm::BIT2D::XS b, IV i1, IV i2, IV value);
153 void bit2d_clear(Algorithm::BIT2D::XS b);