seths / bitunwise (http://blogs.foognostic.net/)

Bitunwise is an algorithm which slowly reads and writes bits in useful ways. Currently just a single C file.

Clone this repository (size: 30.4 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/seths/bitunwise/
commit 8: 1406943a7c8a
parent 7: aea689a7a64e
branch: default
before removing expect
Seth Schroeder
14 months ago

Changed (Δ43 bytes):

raw changeset »

bitunwise.c (16 lines added, 21 lines removed)

Up to file-list bitunwise.c:

@@ -142,14 +142,17 @@ void process(const stream *left, const s
142
142
143
143
/******************************************************************************/
144
144
145
int match(const void *left, const void *right, size_t n, int op, int expect) {
145
int match(const void *left, bytegetter lreader,
146
                 const void *right, bytegetter rreader,
147
                 size_t n, int op, int expect) {
146
148
        match_params params, *ptr;
147
149
        stream lstream, rstream;
148
150
        
149
151
        params.expect = expect;
150
152
        ptr = ¶ms;
151
153
152
        lstream.reader = rstream.reader = nthbyte;
154
        lstream.reader = lreader;
155
        rstream.reader = rreader;
153
156
        lstream.src = left;
154
157
        rstream.src = right;
155
158
        
@@ -159,6 +162,12 @@ int match(const void *left, const void *
159
162
}
160
163
161
164
/******************************************************************************/
165
166
int simple_match(const void *left, const void *right, size_t n, int op, int expect) {
167
        return match(left, nthbyte, right, nthbyte, n, op, expect);
168
}
169
170
/******************************************************************************/
162
171
/* Begin implementation of external functions */
163
172
164
173
void* bu_bzero(void *dst, size_t n) {
@@ -227,38 +236,24 @@ void* bu_invert(void *dst, const void *s
227
236
/******************************************************************************/
228
237
229
238
int bu_memcmp(const void *left, const void *right, size_t n) {
230
        return !match(left, right, n, op_same, 1);
239
        return !simple_match(left, right, n, op_same, 1);
231
240
}
232
241
233
242
/******************************************************************************/
234
243
235
244
int bu_equal(const void *left, const void *right, size_t n) {
236
        return match(left, right, n, op_same, 1);
245
        return simple_match(left, right, n, op_same, 1);
237
246
}
238
247
239
248
/******************************************************************************/
240
249
241
250
int bu_opposite(const void *left, const void *right, size_t n) {
242
        return match(left, right, n, op_different, 1);
251
        return simple_match(left, right, n, op_different, 1);
243
252
}
244
253
245
254
/******************************************************************************/
246
255
247
256
int bu_isset(const void *src, int val, size_t n) {
248
        stream lstream, rstream;
249
        match_params params, *ptr;
250
        u08 pat;
251
        
252
        lstream.reader = nthbyte;
253
        lstream.src = src;
254
255
        pat = val;
256
        rstream.reader = onebyte;
257
        rstream.src = &pat;
258
259
        params.expect = 1;
260
        ptr = ¶ms;
261
        
262
        process(&lstream, &rstream, n, op_same, MATCH, (void**)&ptr);
263
        return params.result;
257
        u08 pat = val;
258
        return match(src, nthbyte, &pat, onebyte, n, op_same, 1);
264
259
}