forked from chrisarg/Bit-Set
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet.xs
More file actions
213 lines (154 loc) · 4.66 KB
/
Set.xs
File metadata and controls
213 lines (154 loc) · 4.66 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "EXTERN.h"
#include "perl.h"
#include "perlapi.h"
#include "XSUB.h"
#include "bit.h"
struct T {
int length; // capacity of the bitset in bits
int size_in_bytes; // number of bytes of the 8 bit container
int size_in_qwords; // number of qwords of the 64 bit container
bool is_Bit_T_allocated; // true if allocated by the library
unsigned char *bytes; // pointer to the first byte
unsigned long long *qwords; // pointer to the first qword
};
MODULE = Bit::Set PACKAGE = Bit::Set PREFIX = BSOO_
PROTOTYPES: disable
void BSOO_new(char *class, IV length, IV n=1)
PPCODE:
EXTEND(SP, n);
struct T *obj = (struct T *) T_alloc(n, length, NULL);
for (IV idx = 0; idx < n; ++idx) {
SV *s = sv_newmortal();
sv_setiv(newSVrv(s, class), PTR2IV(obj+idx));
PUSHs(s);
}
void BSOO_DESTROY(Bit_T obj)
CODE:
Bit_free(&obj);
SV *BSOO_load(char *class, IV length, char *buffer)
CODE:
Bit_T obj = Bit_load(length,(void *)buffer);
ST(0) = sv_newmortal();
sv_setiv(newSVrv(ST(0), class), PTR2IV(obj));
SV *BSOO_extract(Bit_T obj, char *buffer)
CODE:
IV rv = Bit_extract(obj,(void *)buffer);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_buffer_size(char *class, IV length)
CODE:
IV rv = Bit_buffer_size(length);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_length(Bit_T obj)
CODE:
IV rv = Bit_length(obj);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_count(Bit_T obj)
CODE:
IV rv = Bit_count(obj);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
void BSOO_aset(Bit_T obj, SV *indices, IV n)
CODE:
int idx[n];
AV *av = (AV *)SvRV(indices);
STRLEN len = av_len(av);
if (len < n) n = len;
for (int i = 0; i < n; ++i) {
SV **svp = av_fetch(av, i, 0);
idx[i] = SvIV(*svp);
}
Bit_aset(obj, idx, n);
void BSOO_bset(Bit_T obj, IV index)
CODE:
Bit_bset(obj, index);
void BSOO_aclear(Bit_T obj, SV *indices, IV n)
CODE:
int idx[n];
AV *av = (AV *)SvRV(indices);
STRLEN len = av_len(av);
if (len < n) n = len;
for (int i = 0; i < n; ++i) {
SV **svp = av_fetch(av, i, 0);
idx[i] = SvIV(*svp);
}
Bit_aclear(obj, idx, n);
void BSOO_bclear(Bit_T obj, IV index)
CODE:
Bit_bclear(obj, index);
void BSOO_clear(Bit_T obj, IV lo, IV hi)
CODE:
Bit_clear(obj, lo, hi);
SV *BSOO_get(Bit_T obj, IV index)
CODE:
IV rv = Bit_get(obj, index);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
void BSOO_not(Bit_T obj, IV lo, IV hi)
CODE:
Bit_not(obj, lo, hi);
SV *BSOO_put(Bit_T obj, IV index, IV bit)
CODE:
IV rv = Bit_put(obj, index, bit);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
void BSOO_set(Bit_T obj, IV lo, IV hi)
CODE:
Bit_set(obj, lo, hi);
SV *BSOO_eq(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_eq(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_leq(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_leq(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_lt(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_lt(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_diff(Bit_T obj, Bit_T other)
CODE:
Bit_T rv = Bit_diff(obj, other);
ST(0) = sv_newmortal();
sv_setiv(newSVrv(ST(0), "Bit::Set"), PTR2IV(rv));
SV *BSOO_inter(Bit_T obj, Bit_T other)
CODE:
Bit_T rv = Bit_inter(obj, other);
ST(0) = sv_newmortal();
sv_setiv(newSVrv(ST(0), "Bit::Set"), PTR2IV(rv));
SV *BSOO_minus(Bit_T obj, Bit_T other)
CODE:
Bit_T rv = Bit_minus(obj, other);
ST(0) = sv_newmortal();
sv_setiv(newSVrv(ST(0), "Bit::Set"), PTR2IV(rv));
SV *BSOO_union(Bit_T obj, Bit_T other)
CODE:
Bit_T rv = Bit_union(obj, other);
ST(0) = sv_newmortal();
sv_setiv(newSVrv(ST(0), "Bit::Set"), PTR2IV(rv));
SV *BSOO_diff_count(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_diff_count(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_inter_count(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_inter_count(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_minus_count(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_minus_count(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);
SV *BSOO_union_count(Bit_T obj, Bit_T other)
CODE:
IV rv = Bit_union_count(obj, other);
ST(0) = sv_newmortal();
sv_setiv(ST(0), rv);