redrust 0.1.1

redrust is a port of the popular Redis database system written in Rust programming language. This port aims to provide all the features of Redis while taking advantage of the Rust language's safety, speed, and modern language features.
Documentation
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
extern crate c2rust_bitfields;
extern crate libc;
extern crate core;
pub type __uint16_t = libc::c_ushort;
pub type __uint64_t = libc::c_ulong;
pub type uint16_t = __uint16_t;
pub type uint64_t = __uint64_t;
pub type uintptr_t = libc::c_ulong;
pub type size_t = libc::c_ulong;
pub type crcfn64 = Option::<
    unsafe extern "C" fn(uint64_t, *const libc::c_void, uint64_t) -> uint64_t,
>;
pub type crcfn16 = Option::<
    unsafe extern "C" fn(uint16_t, *const libc::c_void, uint64_t) -> uint16_t,
>;
#[no_mangle]
pub unsafe extern "C" fn crcspeed64little_init(
    mut crcfn: crcfn64,
    mut table: *mut [uint64_t; 256],
) {
    let mut crc: uint64_t = 0;
    let mut n: libc::c_int = 0 as libc::c_int;
    while n < 256 as libc::c_int {
        let mut v: libc::c_uchar = n as libc::c_uchar;
        (*table
            .offset(
                0 as libc::c_int as isize,
            ))[n
            as usize] = crcfn
            .expect(
                "non-null function pointer",
            )(
            0 as libc::c_int as uint64_t,
            &mut v as *mut libc::c_uchar as *const libc::c_void,
            1 as libc::c_int as uint64_t,
        );
        n += 1;
    }
    let mut n_0: libc::c_int = 0 as libc::c_int;
    while n_0 < 256 as libc::c_int {
        crc = (*table.offset(0 as libc::c_int as isize))[n_0 as usize];
        let mut k: libc::c_int = 1 as libc::c_int;
        while k < 8 as libc::c_int {
            crc = (*table
                .offset(
                    0 as libc::c_int as isize,
                ))[(crc & 0xff as libc::c_int as libc::c_ulong) as usize]
                ^ crc >> 8 as libc::c_int;
            (*table.offset(k as isize))[n_0 as usize] = crc;
            k += 1;
        }
        n_0 += 1;
    }
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed16little_init(
    mut crcfn: crcfn16,
    mut table: *mut [uint16_t; 256],
) {
    let mut crc: uint16_t = 0;
    let mut n: libc::c_int = 0 as libc::c_int;
    while n < 256 as libc::c_int {
        (*table
            .offset(
                0 as libc::c_int as isize,
            ))[n
            as usize] = crcfn
            .expect(
                "non-null function pointer",
            )(
            0 as libc::c_int as uint16_t,
            &mut n as *mut libc::c_int as *const libc::c_void,
            1 as libc::c_int as uint64_t,
        );
        n += 1;
    }
    let mut n_0: libc::c_int = 0 as libc::c_int;
    while n_0 < 256 as libc::c_int {
        crc = (*table.offset(0 as libc::c_int as isize))[n_0 as usize];
        let mut k: libc::c_int = 1 as libc::c_int;
        while k < 8 as libc::c_int {
            crc = ((*table
                .offset(
                    0 as libc::c_int as isize,
                ))[(crc as libc::c_int >> 8 as libc::c_int & 0xff as libc::c_int)
                as usize] as libc::c_int ^ (crc as libc::c_int) << 8 as libc::c_int)
                as uint16_t;
            (*table.offset(k as isize))[n_0 as usize] = crc;
            k += 1;
        }
        n_0 += 1;
    }
}
#[inline]
unsafe extern "C" fn rev8(mut a: uint64_t) -> uint64_t {
    return a.swap_bytes();
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed64big_init(
    mut fn_0: crcfn64,
    mut big_table: *mut [uint64_t; 256],
) {
    crcspeed64little_init(fn_0, big_table);
    let mut k: libc::c_int = 0 as libc::c_int;
    while k < 8 as libc::c_int {
        let mut n: libc::c_int = 0 as libc::c_int;
        while n < 256 as libc::c_int {
            (*big_table
                .offset(
                    k as isize,
                ))[n as usize] = rev8((*big_table.offset(k as isize))[n as usize]);
            n += 1;
        }
        k += 1;
    }
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed16big_init(
    mut fn_0: crcfn16,
    mut big_table: *mut [uint16_t; 256],
) {
    crcspeed16little_init(fn_0, big_table);
    let mut k: libc::c_int = 0 as libc::c_int;
    while k < 8 as libc::c_int {
        let mut n: libc::c_int = 0 as libc::c_int;
        while n < 256 as libc::c_int {
            (*big_table
                .offset(
                    k as isize,
                ))[n
                as usize] = rev8((*big_table.offset(k as isize))[n as usize] as uint64_t)
                as uint16_t;
            n += 1;
        }
        k += 1;
    }
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed64little(
    mut little_table: *mut [uint64_t; 256],
    mut crc: uint64_t,
    mut buf: *mut libc::c_void,
    mut len: size_t,
) -> uint64_t {
    let mut next: *mut libc::c_uchar = buf as *mut libc::c_uchar;
    while len != 0
        && next as uintptr_t & 7 as libc::c_int as libc::c_ulong
            != 0 as libc::c_int as libc::c_ulong
    {
        let fresh0 = next;
        next = next.offset(1);
        crc = (*little_table
            .offset(
                0 as libc::c_int as isize,
            ))[((crc ^ *fresh0 as libc::c_ulong) & 0xff as libc::c_int as libc::c_ulong)
            as usize] ^ crc >> 8 as libc::c_int;
        len = len.wrapping_sub(1);
    }
    while len >= 8 as libc::c_int as libc::c_ulong {
        crc ^= *(next as *mut uint64_t);
        crc = (*little_table
            .offset(
                7 as libc::c_int as isize,
            ))[(crc & 0xff as libc::c_int as libc::c_ulong) as usize]
            ^ (*little_table
                .offset(
                    6 as libc::c_int as isize,
                ))[(crc >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*little_table
                .offset(
                    5 as libc::c_int as isize,
                ))[(crc >> 16 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*little_table
                .offset(
                    4 as libc::c_int as isize,
                ))[(crc >> 24 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*little_table
                .offset(
                    3 as libc::c_int as isize,
                ))[(crc >> 32 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*little_table
                .offset(
                    2 as libc::c_int as isize,
                ))[(crc >> 40 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*little_table
                .offset(
                    1 as libc::c_int as isize,
                ))[(crc >> 48 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*little_table
                .offset(0 as libc::c_int as isize))[(crc >> 56 as libc::c_int) as usize];
        next = next.offset(8 as libc::c_int as isize);
        len = (len as libc::c_ulong).wrapping_sub(8 as libc::c_int as libc::c_ulong)
            as size_t as size_t;
    }
    while len != 0 {
        let fresh1 = next;
        next = next.offset(1);
        crc = (*little_table
            .offset(
                0 as libc::c_int as isize,
            ))[((crc ^ *fresh1 as libc::c_ulong) & 0xff as libc::c_int as libc::c_ulong)
            as usize] ^ crc >> 8 as libc::c_int;
        len = len.wrapping_sub(1);
    }
    return crc;
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed16little(
    mut little_table: *mut [uint16_t; 256],
    mut crc: uint16_t,
    mut buf: *mut libc::c_void,
    mut len: size_t,
) -> uint16_t {
    let mut next: *mut libc::c_uchar = buf as *mut libc::c_uchar;
    while len != 0
        && next as uintptr_t & 7 as libc::c_int as libc::c_ulong
            != 0 as libc::c_int as libc::c_ulong
    {
        let fresh2 = next;
        next = next.offset(1);
        crc = ((*little_table
            .offset(
                0 as libc::c_int as isize,
            ))[((crc as libc::c_int >> 8 as libc::c_int ^ *fresh2 as libc::c_int)
            & 0xff as libc::c_int) as usize] as libc::c_int
            ^ (crc as libc::c_int) << 8 as libc::c_int) as uint16_t;
        len = len.wrapping_sub(1);
    }
    while len >= 8 as libc::c_int as libc::c_ulong {
        let mut n: uint64_t = *(next as *mut uint64_t);
        crc = ((*little_table
            .offset(
                7 as libc::c_int as isize,
            ))[(n & 0xff as libc::c_int as libc::c_ulong
            ^ (crc as libc::c_int >> 8 as libc::c_int & 0xff as libc::c_int)
                as libc::c_ulong) as usize] as libc::c_int
            ^ (*little_table
                .offset(
                    6 as libc::c_int as isize,
                ))[(n >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_ulong
                ^ (crc as libc::c_int & 0xff as libc::c_int) as libc::c_ulong) as usize]
                as libc::c_int
            ^ (*little_table
                .offset(
                    5 as libc::c_int as isize,
                ))[(n >> 16 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*little_table
                .offset(
                    4 as libc::c_int as isize,
                ))[(n >> 24 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*little_table
                .offset(
                    3 as libc::c_int as isize,
                ))[(n >> 32 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*little_table
                .offset(
                    2 as libc::c_int as isize,
                ))[(n >> 40 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*little_table
                .offset(
                    1 as libc::c_int as isize,
                ))[(n >> 48 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*little_table
                .offset(0 as libc::c_int as isize))[(n >> 56 as libc::c_int) as usize]
                as libc::c_int) as uint16_t;
        next = next.offset(8 as libc::c_int as isize);
        len = (len as libc::c_ulong).wrapping_sub(8 as libc::c_int as libc::c_ulong)
            as size_t as size_t;
    }
    while len != 0 {
        let fresh3 = next;
        next = next.offset(1);
        crc = ((*little_table
            .offset(
                0 as libc::c_int as isize,
            ))[((crc as libc::c_int >> 8 as libc::c_int ^ *fresh3 as libc::c_int)
            & 0xff as libc::c_int) as usize] as libc::c_int
            ^ (crc as libc::c_int) << 8 as libc::c_int) as uint16_t;
        len = len.wrapping_sub(1);
    }
    return crc;
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed64big(
    mut big_table: *mut [uint64_t; 256],
    mut crc: uint64_t,
    mut buf: *mut libc::c_void,
    mut len: size_t,
) -> uint64_t {
    let mut next: *mut libc::c_uchar = buf as *mut libc::c_uchar;
    crc = rev8(crc);
    while len != 0
        && next as uintptr_t & 7 as libc::c_int as libc::c_ulong
            != 0 as libc::c_int as libc::c_ulong
    {
        let fresh4 = next;
        next = next.offset(1);
        crc = (*big_table
            .offset(
                0 as libc::c_int as isize,
            ))[(crc >> 56 as libc::c_int ^ *fresh4 as libc::c_ulong) as usize]
            ^ crc << 8 as libc::c_int;
        len = len.wrapping_sub(1);
    }
    while len >= 8 as libc::c_int as libc::c_ulong {
        crc ^= *(next as *mut uint64_t);
        crc = (*big_table
            .offset(
                0 as libc::c_int as isize,
            ))[(crc & 0xff as libc::c_int as libc::c_ulong) as usize]
            ^ (*big_table
                .offset(
                    1 as libc::c_int as isize,
                ))[(crc >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*big_table
                .offset(
                    2 as libc::c_int as isize,
                ))[(crc >> 16 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*big_table
                .offset(
                    3 as libc::c_int as isize,
                ))[(crc >> 24 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*big_table
                .offset(
                    4 as libc::c_int as isize,
                ))[(crc >> 32 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*big_table
                .offset(
                    5 as libc::c_int as isize,
                ))[(crc >> 40 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*big_table
                .offset(
                    6 as libc::c_int as isize,
                ))[(crc >> 48 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize]
            ^ (*big_table
                .offset(7 as libc::c_int as isize))[(crc >> 56 as libc::c_int) as usize];
        next = next.offset(8 as libc::c_int as isize);
        len = (len as libc::c_ulong).wrapping_sub(8 as libc::c_int as libc::c_ulong)
            as size_t as size_t;
    }
    while len != 0 {
        let fresh5 = next;
        next = next.offset(1);
        crc = (*big_table
            .offset(
                0 as libc::c_int as isize,
            ))[(crc >> 56 as libc::c_int ^ *fresh5 as libc::c_ulong) as usize]
            ^ crc << 8 as libc::c_int;
        len = len.wrapping_sub(1);
    }
    return rev8(crc);
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed16big(
    mut big_table: *mut [uint16_t; 256],
    mut crc_in: uint16_t,
    mut buf: *mut libc::c_void,
    mut len: size_t,
) -> uint16_t {
    let mut next: *mut libc::c_uchar = buf as *mut libc::c_uchar;
    let mut crc: uint64_t = crc_in as uint64_t;
    crc = rev8(crc);
    while len != 0
        && next as uintptr_t & 7 as libc::c_int as libc::c_ulong
            != 0 as libc::c_int as libc::c_ulong
    {
        let fresh6 = next;
        next = next.offset(1);
        crc = (*big_table
            .offset(
                0 as libc::c_int as isize,
            ))[((crc >> 56 as libc::c_int - 8 as libc::c_int ^ *fresh6 as libc::c_ulong)
            & 0xff as libc::c_int as libc::c_ulong) as usize] as libc::c_ulong
            ^ crc >> 8 as libc::c_int;
        len = len.wrapping_sub(1);
    }
    while len >= 8 as libc::c_int as libc::c_ulong {
        let mut n: uint64_t = *(next as *mut uint64_t);
        crc = ((*big_table
            .offset(
                0 as libc::c_int as isize,
            ))[(n & 0xff as libc::c_int as libc::c_ulong
            ^ crc >> 56 as libc::c_int - 8 as libc::c_int
                & 0xff as libc::c_int as libc::c_ulong) as usize] as libc::c_int
            ^ (*big_table
                .offset(
                    1 as libc::c_int as isize,
                ))[(n >> 8 as libc::c_int & 0xff as libc::c_int as libc::c_ulong
                ^ crc & 0xff as libc::c_int as libc::c_ulong) as usize] as libc::c_int
            ^ (*big_table
                .offset(
                    2 as libc::c_int as isize,
                ))[(n >> 16 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*big_table
                .offset(
                    3 as libc::c_int as isize,
                ))[(n >> 24 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*big_table
                .offset(
                    4 as libc::c_int as isize,
                ))[(n >> 32 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*big_table
                .offset(
                    5 as libc::c_int as isize,
                ))[(n >> 40 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*big_table
                .offset(
                    6 as libc::c_int as isize,
                ))[(n >> 48 as libc::c_int & 0xff as libc::c_int as libc::c_ulong)
                as usize] as libc::c_int
            ^ (*big_table
                .offset(7 as libc::c_int as isize))[(n >> 56 as libc::c_int) as usize]
                as libc::c_int) as uint64_t;
        next = next.offset(8 as libc::c_int as isize);
        len = (len as libc::c_ulong).wrapping_sub(8 as libc::c_int as libc::c_ulong)
            as size_t as size_t;
    }
    while len != 0 {
        let fresh7 = next;
        next = next.offset(1);
        crc = (*big_table
            .offset(
                0 as libc::c_int as isize,
            ))[((crc >> 56 as libc::c_int - 8 as libc::c_int ^ *fresh7 as libc::c_ulong)
            & 0xff as libc::c_int as libc::c_ulong) as usize] as libc::c_ulong
            ^ crc >> 8 as libc::c_int;
        len = len.wrapping_sub(1);
    }
    return rev8(crc) as uint16_t;
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed64native(
    mut table: *mut [uint64_t; 256],
    mut crc: uint64_t,
    mut buf: *mut libc::c_void,
    mut len: size_t,
) -> uint64_t {
    let mut n: uint64_t = 1 as libc::c_int as uint64_t;
    return if *(&mut n as *mut uint64_t as *mut libc::c_char) as libc::c_int != 0 {
        crcspeed64little(table, crc, buf, len)
    } else {
        crcspeed64big(table, crc, buf, len)
    };
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed16native(
    mut table: *mut [uint16_t; 256],
    mut crc: uint16_t,
    mut buf: *mut libc::c_void,
    mut len: size_t,
) -> uint16_t {
    let mut n: uint64_t = 1 as libc::c_int as uint64_t;
    return (if *(&mut n as *mut uint64_t as *mut libc::c_char) as libc::c_int != 0 {
        crcspeed16little(table, crc, buf, len) as libc::c_int
    } else {
        crcspeed16big(table, crc, buf, len) as libc::c_int
    }) as uint16_t;
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed64native_init(
    mut fn_0: crcfn64,
    mut table: *mut [uint64_t; 256],
) {
    let mut n: uint64_t = 1 as libc::c_int as uint64_t;
    if *(&mut n as *mut uint64_t as *mut libc::c_char) as libc::c_int != 0 {
        crcspeed64little_init(fn_0, table);
    } else {
        crcspeed64big_init(fn_0, table);
    };
}
#[no_mangle]
pub unsafe extern "C" fn crcspeed16native_init(
    mut fn_0: crcfn16,
    mut table: *mut [uint16_t; 256],
) {
    let mut n: uint64_t = 1 as libc::c_int as uint64_t;
    if *(&mut n as *mut uint64_t as *mut libc::c_char) as libc::c_int != 0 {
        crcspeed16little_init(fn_0, table);
    } else {
        crcspeed16big_init(fn_0, table);
    };
}