Created
July 28, 2014 02:53
-
-
Save lh3/987513841c89dcf79fed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -g -O2 -Wall fmr-rld.c mrope.c rle.c rope.c rld0.c -o fmr-rld -pthread | |
#include <stdio.h> | |
#include <stdint.h> | |
#include "rle.h" | |
#include "rld0.h" | |
#include "mrope.h" | |
int main(int argc, char *argv[]) | |
{ | |
rld_t *e; | |
rlditr_t ie; | |
FILE *fp; | |
mrope_t *r; | |
mritr_t ir; | |
const uint8_t *block; | |
int last_cr = -1; | |
int64_t last_lr = 0, n_runs = 0; | |
if (argc != 3) { | |
fprintf(stderr, "Usage: fmr-rld <in.fmr> <in.fmd>\n"); | |
return 1; | |
} | |
e = rld_restore(argv[2]); | |
rld_itr_init(e, &ie, 0); | |
fp = fopen(argv[1], "rb"); | |
r = mr_restore(fp); | |
fclose(fp); | |
mr_itr_first(r, &ir, 0); | |
while ((block = mr_itr_next_block(&ir)) != 0) { | |
const uint8_t *q = block + 2, *end = block + 2 + *rle_nptr(block); | |
while (q < end) { | |
int cr = 0, ce = 0; | |
int64_t lr, le; | |
rle_dec1(q, cr, lr); | |
if (cr != last_cr) { | |
if (last_cr >= 0) { | |
++n_runs; | |
le = rld_dec(e, &ie, &ce, 0); | |
if (ce != last_cr || le != last_lr) { | |
fprintf(stderr, "[%ld] %d:%ld != %d:%ld\n", n_runs, ce, le, cr, lr); | |
return 1; | |
} | |
} | |
last_cr = cr; last_lr = 0; | |
} | |
last_lr += lr; | |
} | |
} | |
// TODO: check the last run | |
mr_destroy(r); | |
rld_destroy(e); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include "rld0.h" | |
int main(int argc, char *argv[]) | |
{ | |
rlditr_t itr; | |
rld_t *e; | |
int64_t l, cnt[8]; | |
int c; | |
if (argc == 1) { | |
fprintf(stderr, "Usage: readrld <file.rld>\n"); | |
return 1; | |
} | |
for (c = 0; c < 8; ++c) cnt[c] = 0; | |
e = rld_restore(argv[1]); | |
rld_itr_init(e, &itr, 0); | |
while ((l = rld_dec(e, &itr, &c, 0)) > 0) cnt[c] += l; | |
for (c = 0; c < 8; ++c) | |
printf("%d\t%ld\t%ld\n", c, cnt[c], c < e->asize? e->mcnt[c+1] : 0); | |
rld_destroy(e); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment