gendata_h48short_tests.c (1395B)
1 #include "../test.h" 2 3 #define MAXPOS 200 4 5 void h48map_create(h48map_t *, uint64_t, uint64_t); 6 void h48map_destroy(h48map_t *); 7 kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); 8 size_t gendata_cocsep(void *, uint64_t *, cube_t *); 9 uint64_t gendata_h48short(gendata_h48short_arg_t *); 10 11 char str[STRLENMAX]; 12 13 int compare(const void *x, const void *y) { 14 uint64_t a = ((kvpair_t *)x)->key; 15 uint64_t b = ((kvpair_t *)y)->key; 16 17 if (a > b) return 1; 18 if (a == b) return 0; 19 return -1; 20 } 21 22 uint64_t readl(void) { 23 fgets(str, STRLENMAX, stdin); 24 return atoll(str); 25 } 26 27 void run(void) { 28 char buf[2000000]; 29 h48map_t map; 30 uint64_t i, j, capacity, randomizer, selfsim[COCSEP_CLASSES]; 31 kvpair_t kv, b[MAXPOS]; 32 gendata_h48short_arg_t arg; 33 cube_t crep[COCSEP_CLASSES]; 34 35 capacity = readl(); 36 randomizer = readl(); 37 arg.maxdepth = readl(); 38 arg.crep = crep; 39 arg.selfsim = selfsim; 40 arg.map = ↦ 41 42 h48map_create(&map, capacity, randomizer); 43 gendata_cocsep(buf, selfsim, crep); 44 arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); 45 gendata_h48short(&arg); 46 47 i = 0; 48 for (kv = h48map_nextkvpair(&map, &i), j = 0; 49 i != map.capacity && j < MAXPOS; 50 kv = h48map_nextkvpair(&map, &i) 51 ) { 52 b[j++] = kv; 53 } 54 qsort(b, j, sizeof(kvpair_t), compare); 55 56 printf("%" PRIu64 "\n", map.n); 57 for (i = 0; i < j; i++) 58 printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val); 59 60 h48map_destroy(&map); 61 }