diff options
| -rw-r--r-- | TODO.txt | 34 | ||||
| -rw-r--r-- | src/solve_h48.h | 180 | ||||
| -rw-r--r-- | src/utils.h | 2 | ||||
| -rw-r--r-- | test/112_h48map/00_small.in | 11 | ||||
| -rw-r--r-- | test/112_h48map/00_small.out | 3 | ||||
| -rw-r--r-- | test/112_h48map/01_large.in (renamed from test/112_h48set/01_large.in) | 150 | ||||
| -rw-r--r-- | test/112_h48map/01_large.out | 83 | ||||
| -rw-r--r-- | test/112_h48map/h48map_tests.c | 88 | ||||
| -rw-r--r-- | test/112_h48set/00_small.in | 6 | ||||
| -rw-r--r-- | test/112_h48set/00_small.out | 3 | ||||
| -rw-r--r-- | test/112_h48set/01_large.out | 83 | ||||
| -rw-r--r-- | test/112_h48set/h48set_tests.c | 64 |
12 files changed, 483 insertions, 224 deletions
| @@ -1,14 +1,38 @@ | |||
| 1 | Bug in esep table generation | 1 | Bug in esep table generation |
| 2 | - Re-do stats | 2 | - add pre-computation of h48 coordinates at distance <=7? |
| 3 | - unit tests (but how do I test? just leave it there to check regressions) | ||
| 3 | - Add long-running test for h0k4 (maybe as a tool?) | 4 | - Add long-running test for h0k4 (maybe as a tool?) |
| 4 | - try DFS for h0 solver | 5 | - compute all tables for h<11 |
| 5 | - use dfs for computing big table, save distance %3 until the last two steps, | 6 | - compute visited up to a fixed depth (7? 8?) |
| 6 | then clean the table and double loop over moves to fill the value | 7 | - compute additional step (if needed) to fill <=base |
| 7 | - dfs for tables with h=1 to 10? | 8 | - brute-force the last 2 steps (only 18 moves + 18*15 move pairs) |
| 9 | - compare with known h0 results (from long-running test) | ||
| 10 | - compute table for h=11 | ||
| 11 | - is is worth pre-computing stuff? | ||
| 12 | - can it be unified to the other computation, or is it much better | ||
| 13 | to do it ad hoc? | ||
| 14 | - optimize | ||
| 15 | - use cached values for invcoord_esep? check if it is faster | ||
| 8 | 16 | ||
| 17 | (OLD: | ||
| 9 | - Fails for UFRUFU, try command | 18 | - Fails for UFRUFU, try command |
| 10 | ./run solve -solver H48 -options "2;20" -n 1 -M 10 -cube \ | 19 | ./run solve -solver H48 -options "2;20" -n 1 -M 10 -cube \ |
| 11 | "$(./run frommoves -moves "UFRUFU")" | 20 | "$(./run frommoves -moves "UFRUFU")" |
| 21 | ) | ||
| 22 | |||
| 23 | table base for k=2 (4 most common values start at) | ||
| 24 | 0 8 | ||
| 25 | 1 8 | ||
| 26 | 2 8 | ||
| 27 | 3 8 or 9 (very close) | ||
| 28 | 4 9 | ||
| 29 | 5 9 | ||
| 30 | 6 9 | ||
| 31 | 7 9 or 10 (very close) | ||
| 32 | 8 10 | ||
| 33 | 9 10 | ||
| 34 | 10 10 | ||
| 35 | 11 11 | ||
| 12 | 36 | ||
| 13 | Solver | 37 | Solver |
| 14 | - cleanup h48 solver | 38 | - cleanup h48 solver |
diff --git a/src/solve_h48.h b/src/solve_h48.h index ed63209..c7cc91c 100644 --- a/src/solve_h48.h +++ b/src/solve_h48.h | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | #define MAP_UNSET UINT64_C(0xFFFFFFFFFFFFFFFF) | ||
| 2 | #define MAP_KEYMASK UINT64_C(0xFFFFFFFFFF) | ||
| 3 | #define MAP_KEYSHIFT UINT64_C(40) | ||
| 4 | |||
| 1 | #define COCSEP_CLASSES ((size_t)3393) | 5 | #define COCSEP_CLASSES ((size_t)3393) |
| 2 | #define COCSEP_TABLESIZE ((size_t)_3p7 << (size_t)7) | 6 | #define COCSEP_TABLESIZE ((size_t)_3p7 << (size_t)7) |
| 3 | #define COCSEP_VISITEDSIZE ((COCSEP_TABLESIZE + (size_t)7) / (size_t)8) | 7 | #define COCSEP_VISITEDSIZE ((COCSEP_TABLESIZE + (size_t)7) / (size_t)8) |
| @@ -24,11 +28,16 @@ | |||
| 24 | #define MAX_SOLUTION_LENGTH 20 | 28 | #define MAX_SOLUTION_LENGTH 20 |
| 25 | 29 | ||
| 26 | typedef struct { | 30 | typedef struct { |
| 27 | int64_t n; | 31 | uint64_t n; |
| 28 | int64_t capacity; | 32 | uint64_t capacity; |
| 29 | int64_t mod; | 33 | uint64_t mod; |
| 30 | int64_t *table; | 34 | uint64_t *table; |
| 31 | } h48set_t; | 35 | } h48map_t; |
| 36 | |||
| 37 | typedef struct { | ||
| 38 | uint64_t key; | ||
| 39 | uint64_t val; | ||
| 40 | } kvpair_t; | ||
| 32 | 41 | ||
| 33 | typedef struct { | 42 | typedef struct { |
| 34 | cube_t cube; | 43 | cube_t cube; |
| @@ -41,6 +50,16 @@ typedef struct { | |||
| 41 | cube_t *rep; | 50 | cube_t *rep; |
| 42 | } dfsarg_cocsep_t; | 51 | } dfsarg_cocsep_t; |
| 43 | 52 | ||
| 53 | /* TODO keep or not? */ | ||
| 54 | typedef struct { | ||
| 55 | cube_t cube; | ||
| 56 | int8_t nmoves; | ||
| 57 | int8_t depth; | ||
| 58 | uint8_t moves[MAX_SOLUTION_LENGTH]; | ||
| 59 | uint32_t *cocsepdata; | ||
| 60 | h48map_t *visited; | ||
| 61 | } dfsarg_genh48set_t; | ||
| 62 | |||
| 44 | typedef struct { | 63 | typedef struct { |
| 45 | uint8_t depth; | 64 | uint8_t depth; |
| 46 | uint32_t *cocsepdata; | 65 | uint32_t *cocsepdata; |
| @@ -74,30 +93,31 @@ typedef struct { | |||
| 74 | char *s; | 93 | char *s; |
| 75 | } dfsarg_solveh48stats_t; | 94 | } dfsarg_solveh48stats_t; |
| 76 | 95 | ||
| 77 | _static void h48set_create(h48set_t *, int64_t, int64_t); | 96 | _static void h48map_create(h48map_t *, uint64_t, uint64_t); |
| 78 | _static void h48set_clear(h48set_t *); | 97 | _static void h48map_clear(h48map_t *); |
| 79 | _static void h48set_destroy(h48set_t *); | 98 | _static void h48map_destroy(h48map_t *); |
| 80 | _static_inline int64_t h48set_lookup(h48set_t *, int64_t); | 99 | _static uint64_t h48map_lookup(h48map_t *, uint64_t); |
| 81 | _static_inline void h48set_insert(h48set_t *, int64_t); | 100 | _static void h48map_insertmin(h48map_t *, uint64_t, uint64_t); |
| 82 | _static_inline bool h48set_contains(h48set_t *, int64_t); | 101 | _static uint64_t h48map_value(h48map_t *, uint64_t); |
| 83 | _static inline int64_t h48set_save(h48set_t *, int64_t *); | 102 | _static kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); |
| 84 | 103 | ||
| 85 | _static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t); | 104 | _static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t); |
| 86 | _static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); | 105 | _static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); |
| 87 | _static_inline cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); | 106 | _static_inline cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); |
| 88 | 107 | ||
| 108 | _static_inline bool get_visited(const uint8_t *, int64_t); | ||
| 109 | _static_inline void set_visited(uint8_t *, int64_t); | ||
| 110 | _static_inline uint8_t get_esep_pval(const uint32_t *, int64_t); | ||
| 111 | _static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t); | ||
| 112 | |||
| 89 | _static size_t gendata_cocsep(void *, uint64_t *, cube_t *); | 113 | _static size_t gendata_cocsep(void *, uint64_t *, cube_t *); |
| 90 | _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); | 114 | _static uint32_t gendata_cocsep_dfs(dfsarg_cocsep_t *); |
| 115 | _static int64_t gen_h48map_short(uint8_t, const uint32_t *, h48map_t *); | ||
| 91 | _static size_t gendata_h48h0k4(void *, uint8_t); | 116 | _static size_t gendata_h48h0k4(void *, uint8_t); |
| 92 | _static int64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); | 117 | _static int64_t gendata_h48h0k4_bfs(bfsarg_esep_t *); |
| 93 | _static int64_t gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *); | 118 | _static int64_t gendata_h48h0k4_bfs_fromdone(bfsarg_esep_t *); |
| 94 | _static int64_t gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *); | 119 | _static int64_t gendata_h48h0k4_bfs_fromnew(bfsarg_esep_t *); |
| 95 | 120 | ||
| 96 | _static_inline bool get_visited(const uint8_t *, int64_t); | ||
| 97 | _static_inline void set_visited(uint8_t *, int64_t); | ||
| 98 | _static_inline uint8_t get_esep_pval(const uint32_t *, int64_t); | ||
| 99 | _static_inline void set_esep_pval(uint32_t *, int64_t, uint8_t); | ||
| 100 | |||
| 101 | _static void solve_h48_appendsolution(dfsarg_solveh48_t *); | 121 | _static void solve_h48_appendsolution(dfsarg_solveh48_t *); |
| 102 | _static_inline int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); | 122 | _static_inline int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); |
| 103 | _static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint32_t *); | 123 | _static_inline int8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint32_t *); |
| @@ -109,78 +129,84 @@ _static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); | |||
| 109 | _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); | 129 | _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); |
| 110 | 130 | ||
| 111 | _static void | 131 | _static void |
| 112 | h48set_create(h48set_t *set, int64_t capacity, int64_t mod) | 132 | h48map_create(h48map_t *map, uint64_t capacity, uint64_t mod) |
| 113 | { | 133 | { |
| 114 | set->capacity = capacity; | 134 | map->capacity = capacity; |
| 115 | set->mod = mod; | 135 | map->mod = mod; |
| 116 | 136 | ||
| 117 | set->table = malloc(set->capacity * sizeof(int64_t)); | 137 | map->table = malloc(map->capacity * sizeof(int64_t)); |
| 118 | h48set_clear(set); | 138 | h48map_clear(map); |
| 119 | } | 139 | } |
| 120 | 140 | ||
| 121 | _static void | 141 | _static void |
| 122 | h48set_clear(h48set_t *set) | 142 | h48map_clear(h48map_t *map) |
| 123 | { | 143 | { |
| 124 | int64_t i; | 144 | memset(map->table, 0xFF, map->capacity * sizeof(uint64_t)); |
| 125 | 145 | map->n = 0; | |
| 126 | for (i = 0; i < set->capacity; i++) | ||
| 127 | set->table[i] = -1; | ||
| 128 | |||
| 129 | set->n = 0; | ||
| 130 | } | 146 | } |
| 131 | 147 | ||
| 132 | _static void | 148 | _static void |
| 133 | h48set_destroy(h48set_t *set) | 149 | h48map_destroy(h48map_t *map) |
| 134 | { | 150 | { |
| 135 | free(set->table); | 151 | free(map->table); |
| 136 | } | 152 | } |
| 137 | 153 | ||
| 138 | /* Returns the index in where x should be inserted, or -1 if x is in the set */ | 154 | _static_inline uint64_t |
| 139 | _static_inline int64_t | 155 | h48map_lookup(h48map_t *map, uint64_t x) |
| 140 | h48set_lookup(h48set_t *set, int64_t x) | ||
| 141 | { | 156 | { |
| 142 | int64_t hash, i; | 157 | uint64_t hash, i; |
| 143 | 158 | ||
| 144 | hash = ((x % set->capacity) * set->mod) % set->capacity; | 159 | hash = ((x % map->capacity) * map->mod) % map->capacity; |
| 145 | for (i = hash; set->table[i] != -1; i = (i+1) % set->capacity) | 160 | for (i = hash; |
| 146 | if (set->table[i] == x) | 161 | map->table[i] != MAP_UNSET && (map->table[i] & MAP_KEYMASK) != x; |
| 147 | return -1; | 162 | i = (i+1) % map->capacity |
| 163 | ) ; | ||
| 148 | 164 | ||
| 149 | return i; | 165 | return i; |
| 150 | } | 166 | } |
| 151 | 167 | ||
| 152 | _static_inline void | 168 | _static_inline void |
| 153 | h48set_insert(h48set_t *set, int64_t x) | 169 | h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) |
| 154 | { | 170 | { |
| 155 | int64_t i; | 171 | uint64_t i, oldval, min; |
| 156 | 172 | ||
| 157 | i = h48set_lookup(set, x); | 173 | i = h48map_lookup(map, key); |
| 158 | if (i != -1) { | 174 | oldval = map->table[i] >> MAP_KEYSHIFT; |
| 159 | set->table[i] = x; | 175 | min = _min(val, oldval); |
| 160 | set->n++; | 176 | |
| 161 | } | 177 | map->n += map->table[i] == MAP_UNSET; |
| 178 | map->table[i] = (key & MAP_KEYMASK) | (min << MAP_KEYSHIFT); | ||
| 162 | } | 179 | } |
| 163 | 180 | ||
| 164 | _static_inline bool | 181 | _static_inline uint64_t |
| 165 | h48set_contains(h48set_t *set, int64_t x) | 182 | h48map_value(h48map_t *map, uint64_t key) |
| 166 | { | 183 | { |
| 167 | int64_t i; | 184 | return map->table[h48map_lookup(map, key)] >> MAP_KEYSHIFT; |
| 168 | |||
| 169 | i = h48set_lookup(set, x); | ||
| 170 | |||
| 171 | return i == -1; | ||
| 172 | } | 185 | } |
| 173 | 186 | ||
| 174 | _static int64_t | 187 | _static kvpair_t |
| 175 | h48set_save(h48set_t *set, int64_t *a) | 188 | h48map_nextkvpair(h48map_t *map, uint64_t *p) |
| 176 | { | 189 | { |
| 177 | int64_t i, j; | 190 | kvpair_t kv; |
| 191 | uint64_t pair; | ||
| 192 | |||
| 193 | kv.key = MAP_UNSET; | ||
| 194 | kv.val = MAP_UNSET; | ||
| 178 | 195 | ||
| 179 | for (i = 0, j = 0; i < set->capacity; i++) | 196 | DBG_ASSERT(*p < map->capacity, kv, |
| 180 | if (set->table[i] != -1) | 197 | "Error looping over map: given index %" PRIu64 " is out of " |
| 181 | a[j++] = set->table[i]; | 198 | "range [0,%" PRIu64 "]", *p, map->capacity); |
| 182 | 199 | ||
| 183 | return j; | 200 | for ( ; *p < map->capacity; (*p)++) { |
| 201 | if (map->table[*p] != MAP_UNSET) { | ||
| 202 | pair = map->table[(*p)++]; | ||
| 203 | kv.key = pair & MAP_KEYMASK; | ||
| 204 | kv.val = pair >> MAP_KEYSHIFT; | ||
| 205 | return kv; | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | return kv; | ||
| 184 | } | 210 | } |
| 185 | 211 | ||
| 186 | _static_inline int64_t | 212 | _static_inline int64_t |
| @@ -358,6 +384,34 @@ gendata_cocsep_dfs(dfsarg_cocsep_t *arg) | |||
| 358 | return cc; | 384 | return cc; |
| 359 | } | 385 | } |
| 360 | 386 | ||
| 387 | _static int64_t | ||
| 388 | gen_h48map_short(uint8_t n, const uint32_t *cocsepdata, h48map_t *map) | ||
| 389 | { | ||
| 390 | /* | ||
| 391 | uint8_t i, j, m; | ||
| 392 | int64_t coord; | ||
| 393 | cube_t cube, d; | ||
| 394 | |||
| 395 | cube = solvedcube(); | ||
| 396 | coord = coord_h48(cube, cocsepdata, 11); | ||
| 397 | for (i = 0; i < n; i++) { | ||
| 398 | for (j = 0; (coord = h48map_next(map, &j)) != -1; ) { | ||
| 399 | cube = invcoord_h48(coord, cocsepdata, 11); | ||
| 400 | for (m = 0; m < 18; m++) { | ||
| 401 | d = move(cube, m); | ||
| 402 | TODO | ||
| 403 | } | ||
| 404 | } | ||
| 405 | } | ||
| 406 | */ | ||
| 407 | } | ||
| 408 | |||
| 409 | _static int64_t | ||
| 410 | gen_h48set_short_dfs(dfsarg_genh48set_t *arg) | ||
| 411 | { | ||
| 412 | /* TODO */ | ||
| 413 | } | ||
| 414 | |||
| 361 | /* | 415 | /* |
| 362 | TODO description | 416 | TODO description |
| 363 | generating fixed table with h=0, k=4 | 417 | generating fixed table with h=0, k=4 |
| @@ -756,9 +810,9 @@ solve_h48stats( | |||
| 756 | for (i = 0; i < 12; i++) | 810 | for (i = 0; i < 12; i++) |
| 757 | solutions[i] = (char)99; | 811 | solutions[i] = (char)99; |
| 758 | 812 | ||
| 759 | for (arg.depth = 0; | 813 | for (arg.depth = 0; |
| 760 | arg.depth <= maxmoves && solutions[11] == 99; | 814 | arg.depth <= maxmoves && solutions[11] == 99; |
| 761 | arg.depth++) | 815 | arg.depth++) |
| 762 | { | 816 | { |
| 763 | arg.nmoves = 0; | 817 | arg.nmoves = 0; |
| 764 | solve_h48stats_dfs(&arg); | 818 | solve_h48stats_dfs(&arg); |
diff --git a/src/utils.h b/src/utils.h index 021ca75..87402e6 100644 --- a/src/utils.h +++ b/src/utils.h | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | #define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) | 1 | #define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) |
| 2 | #define _min(x, y) ((x) < (y) ? (x) : (y)) | ||
| 3 | #define _max(x, y) ((x) > (y) ? (x) : (y)) | ||
| 2 | 4 | ||
| 3 | _static int64_t factorial(int64_t); | 5 | _static int64_t factorial(int64_t); |
| 4 | _static bool isperm(uint8_t *, int64_t); | 6 | _static bool isperm(uint8_t *, int64_t); |
diff --git a/test/112_h48map/00_small.in b/test/112_h48map/00_small.in new file mode 100644 index 0000000..ee8e591 --- /dev/null +++ b/test/112_h48map/00_small.in | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | 11 | ||
| 2 | 7 | ||
| 3 | 4 | ||
| 4 | 34 | ||
| 5 | 12 | ||
| 6 | 45 | ||
| 7 | 7 | ||
| 8 | 34 | ||
| 9 | 13 | ||
| 10 | 45 | ||
| 11 | 5 | ||
diff --git a/test/112_h48map/00_small.out b/test/112_h48map/00_small.out new file mode 100644 index 0000000..260e804 --- /dev/null +++ b/test/112_h48map/00_small.out | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | 2 | ||
| 2 | 34 12 | ||
| 3 | 45 5 | ||
diff --git a/test/112_h48set/01_large.in b/test/112_h48map/01_large.in index a70ef9a..1812b40 100644 --- a/test/112_h48set/01_large.in +++ b/test/112_h48map/01_large.in | |||
| @@ -2,152 +2,302 @@ | |||
| 2 | 293 | 2 | 293 |
| 3 | 150 | 3 | 150 |
| 4 | 100053 | 4 | 100053 |
| 5 | 417 | ||
| 5 | 100045 | 6 | 100045 |
| 7 | 164 | ||
| 6 | 100007 | 8 | 100007 |
| 9 | 235 | ||
| 7 | 100007 | 10 | 100007 |
| 11 | 207 | ||
| 8 | 100011 | 12 | 100011 |
| 13 | 406 | ||
| 9 | 100072 | 14 | 100072 |
| 15 | 29 | ||
| 10 | 100033 | 16 | 100033 |
| 17 | 188 | ||
| 11 | 100015 | 18 | 100015 |
| 19 | 358 | ||
| 12 | 100013 | 20 | 100013 |
| 21 | 248 | ||
| 13 | 100068 | 22 | 100068 |
| 23 | 218 | ||
| 14 | 100047 | 24 | 100047 |
| 25 | 398 | ||
| 15 | 100046 | 26 | 100046 |
| 27 | 263 | ||
| 16 | 100000 | 28 | 100000 |
| 29 | 471 | ||
| 17 | 100076 | 30 | 100076 |
| 31 | 219 | ||
| 18 | 100021 | 32 | 100021 |
| 33 | 115 | ||
| 19 | 100019 | 34 | 100019 |
| 35 | 329 | ||
| 20 | 100015 | 36 | 100015 |
| 37 | 178 | ||
| 21 | 100049 | 38 | 100049 |
| 39 | 59 | ||
| 22 | 100052 | 40 | 100052 |
| 41 | 319 | ||
| 23 | 100071 | 42 | 100071 |
| 43 | 232 | ||
| 24 | 100058 | 44 | 100058 |
| 45 | 174 | ||
| 25 | 100009 | 46 | 100009 |
| 47 | 46 | ||
| 26 | 100060 | 48 | 100060 |
| 49 | 349 | ||
| 27 | 100030 | 50 | 100030 |
| 51 | 287 | ||
| 28 | 100051 | 52 | 100051 |
| 53 | 203 | ||
| 29 | 100069 | 54 | 100069 |
| 55 | 359 | ||
| 30 | 100011 | 56 | 100011 |
| 57 | 296 | ||
| 31 | 100051 | 58 | 100051 |
| 59 | 223 | ||
| 32 | 100014 | 60 | 100014 |
| 61 | 233 | ||
| 33 | 100031 | 62 | 100031 |
| 63 | 264 | ||
| 34 | 100017 | 64 | 100017 |
| 65 | 180 | ||
| 35 | 100076 | 66 | 100076 |
| 67 | 22 | ||
| 36 | 100016 | 68 | 100016 |
| 69 | 213 | ||
| 37 | 100030 | 70 | 100030 |
| 71 | 55 | ||
| 38 | 100037 | 72 | 100037 |
| 73 | 3 | ||
| 39 | 100011 | 74 | 100011 |
| 75 | 467 | ||
| 40 | 100002 | 76 | 100002 |
| 77 | 165 | ||
| 41 | 100029 | 78 | 100029 |
| 79 | 161 | ||
| 42 | 100022 | 80 | 100022 |
| 81 | 67 | ||
| 43 | 100038 | 82 | 100038 |
| 83 | 374 | ||
| 44 | 100075 | 84 | 100075 |
| 85 | 4 | ||
| 45 | 100066 | 86 | 100066 |
| 87 | 156 | ||
| 46 | 100051 | 88 | 100051 |
| 89 | 144 | ||
| 47 | 100020 | 90 | 100020 |
| 91 | 480 | ||
| 48 | 100039 | 92 | 100039 |
| 93 | 265 | ||
| 49 | 100029 | 94 | 100029 |
| 95 | 195 | ||
| 50 | 100087 | 96 | 100087 |
| 97 | 245 | ||
| 51 | 100099 | 98 | 100099 |
| 99 | 287 | ||
| 52 | 100041 | 100 | 100041 |
| 101 | 308 | ||
| 53 | 100042 | 102 | 100042 |
| 103 | 32 | ||
| 54 | 100026 | 104 | 100026 |
| 105 | 312 | ||
| 55 | 100060 | 106 | 100060 |
| 107 | 434 | ||
| 56 | 100006 | 108 | 100006 |
| 109 | 392 | ||
| 57 | 100010 | 110 | 100010 |
| 111 | 269 | ||
| 58 | 100079 | 112 | 100079 |
| 113 | 414 | ||
| 59 | 100046 | 114 | 100046 |
| 115 | 161 | ||
| 60 | 100086 | 116 | 100086 |
| 117 | 139 | ||
| 61 | 100010 | 118 | 100010 |
| 119 | 88 | ||
| 62 | 100036 | 120 | 100036 |
| 121 | 117 | ||
| 63 | 100047 | 122 | 100047 |
| 123 | 376 | ||
| 64 | 100069 | 124 | 100069 |
| 125 | 17 | ||
| 65 | 100041 | 126 | 100041 |
| 127 | 314 | ||
| 66 | 100074 | 128 | 100074 |
| 129 | 320 | ||
| 67 | 100090 | 130 | 100090 |
| 131 | 225 | ||
| 68 | 100092 | 132 | 100092 |
| 133 | 424 | ||
| 69 | 100020 | 134 | 100020 |
| 135 | 325 | ||
| 70 | 100096 | 136 | 100096 |
| 137 | 318 | ||
| 71 | 100046 | 138 | 100046 |
| 139 | 238 | ||
| 72 | 100028 | 140 | 100028 |
| 141 | 13 | ||
| 73 | 100072 | 142 | 100072 |
| 143 | 73 | ||
| 74 | 100096 | 144 | 100096 |
| 145 | 262 | ||
| 75 | 100025 | 146 | 100025 |
| 147 | 82 | ||
| 76 | 100001 | 148 | 100001 |
| 149 | 107 | ||
| 77 | 100067 | 150 | 100067 |
| 151 | 410 | ||
| 78 | 100044 | 152 | 100044 |
| 153 | 449 | ||
| 79 | 100063 | 154 | 100063 |
| 155 | 276 | ||
| 80 | 100026 | 156 | 100026 |
| 157 | 392 | ||
| 81 | 100062 | 158 | 100062 |
| 159 | 407 | ||
| 82 | 100091 | 160 | 100091 |
| 161 | 411 | ||
| 83 | 100012 | 162 | 100012 |
| 163 | 400 | ||
| 84 | 100073 | 164 | 100073 |
| 165 | 331 | ||
| 85 | 100051 | 166 | 100051 |
| 167 | 83 | ||
| 86 | 100010 | 168 | 100010 |
| 169 | 385 | ||
| 87 | 100096 | 170 | 100096 |
| 171 | 484 | ||
| 88 | 100043 | 172 | 100043 |
| 173 | 352 | ||
| 89 | 100025 | 174 | 100025 |
| 175 | 207 | ||
| 90 | 100077 | 176 | 100077 |
| 177 | 272 | ||
| 91 | 100089 | 178 | 100089 |
| 179 | 192 | ||
| 92 | 100005 | 180 | 100005 |
| 181 | 291 | ||
| 93 | 100024 | 182 | 100024 |
| 183 | 243 | ||
| 94 | 100091 | 184 | 100091 |
| 185 | 445 | ||
| 95 | 100046 | 186 | 100046 |
| 187 | 162 | ||
| 96 | 100053 | 188 | 100053 |
| 189 | 380 | ||
| 97 | 100058 | 190 | 100058 |
| 191 | 157 | ||
| 98 | 100065 | 192 | 100065 |
| 193 | 464 | ||
| 99 | 100051 | 194 | 100051 |
| 195 | 306 | ||
| 100 | 100056 | 196 | 100056 |
| 197 | 236 | ||
| 101 | 100025 | 198 | 100025 |
| 199 | 198 | ||
| 102 | 100093 | 200 | 100093 |
| 201 | 230 | ||
| 103 | 100088 | 202 | 100088 |
| 203 | 494 | ||
| 104 | 100033 | 204 | 100033 |
| 205 | 70 | ||
| 105 | 100073 | 206 | 100073 |
| 207 | 218 | ||
| 106 | 100048 | 208 | 100048 |
| 209 | 486 | ||
| 107 | 100059 | 210 | 100059 |
| 211 | 77 | ||
| 108 | 100027 | 212 | 100027 |
| 213 | 142 | ||
| 109 | 100045 | 214 | 100045 |
| 215 | 418 | ||
| 110 | 100012 | 216 | 100012 |
| 217 | 68 | ||
| 111 | 100059 | 218 | 100059 |
| 219 | 448 | ||
| 112 | 100084 | 220 | 100084 |
| 221 | 339 | ||
| 113 | 100017 | 222 | 100017 |
| 223 | 39 | ||
| 114 | 100048 | 224 | 100048 |
| 225 | 83 | ||
| 115 | 100004 | 226 | 100004 |
| 227 | 321 | ||
| 116 | 100051 | 228 | 100051 |
| 229 | 441 | ||
| 117 | 100016 | 230 | 100016 |
| 231 | 308 | ||
| 118 | 100088 | 232 | 100088 |
| 233 | 334 | ||
| 119 | 100033 | 234 | 100033 |
| 235 | 476 | ||
| 120 | 100064 | 236 | 100064 |
| 237 | 51 | ||
| 121 | 100060 | 238 | 100060 |
| 239 | 324 | ||
| 122 | 100043 | 240 | 100043 |
| 241 | 149 | ||
| 123 | 100084 | 242 | 100084 |
| 243 | 116 | ||
| 124 | 100026 | 244 | 100026 |
| 245 | 351 | ||
| 125 | 100051 | 246 | 100051 |
| 247 | 396 | ||
| 126 | 100060 | 248 | 100060 |
| 249 | 377 | ||
| 127 | 100069 | 250 | 100069 |
| 251 | 301 | ||
| 128 | 100015 | 252 | 100015 |
| 253 | 319 | ||
| 129 | 100014 | 254 | 100014 |
| 255 | 466 | ||
| 130 | 100038 | 256 | 100038 |
| 257 | 194 | ||
| 131 | 100068 | 258 | 100068 |
| 259 | 41 | ||
| 132 | 100038 | 260 | 100038 |
| 261 | 295 | ||
| 133 | 100097 | 262 | 100097 |
| 263 | 394 | ||
| 134 | 100017 | 264 | 100017 |
| 265 | 34 | ||
| 135 | 100013 | 266 | 100013 |
| 267 | 223 | ||
| 136 | 100053 | 268 | 100053 |
| 269 | 339 | ||
| 137 | 100019 | 270 | 100019 |
| 271 | 67 | ||
| 138 | 100018 | 272 | 100018 |
| 273 | 24 | ||
| 139 | 100081 | 274 | 100081 |
| 275 | 205 | ||
| 140 | 100071 | 276 | 100071 |
| 277 | 440 | ||
| 141 | 100025 | 278 | 100025 |
| 279 | 228 | ||
| 142 | 100014 | 280 | 100014 |
| 281 | 169 | ||
| 143 | 100016 | 282 | 100016 |
| 283 | 121 | ||
| 144 | 100011 | 284 | 100011 |
| 285 | 444 | ||
| 145 | 100069 | 286 | 100069 |
| 287 | 460 | ||
| 146 | 100079 | 288 | 100079 |
| 289 | 139 | ||
| 147 | 100063 | 290 | 100063 |
| 291 | 169 | ||
| 148 | 100070 | 292 | 100070 |
| 293 | 132 | ||
| 149 | 100072 | 294 | 100072 |
| 295 | 119 | ||
| 150 | 100095 | 296 | 100095 |
| 297 | 126 | ||
| 151 | 100042 | 298 | 100042 |
| 299 | 217 | ||
| 152 | 100008 | 300 | 100008 |
| 301 | 272 | ||
| 153 | 100022 | 302 | 100022 |
| 303 | 121 | ||
diff --git a/test/112_h48map/01_large.out b/test/112_h48map/01_large.out new file mode 100644 index 0000000..f5e00d8 --- /dev/null +++ b/test/112_h48map/01_large.out | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | 82 | ||
| 2 | 100000 471 | ||
| 3 | 100001 107 | ||
| 4 | 100002 165 | ||
| 5 | 100004 321 | ||
| 6 | 100005 291 | ||
| 7 | 100006 392 | ||
| 8 | 100007 207 | ||
| 9 | 100008 272 | ||
| 10 | 100009 46 | ||
| 11 | 100010 88 | ||
| 12 | 100011 296 | ||
| 13 | 100012 68 | ||
| 14 | 100013 223 | ||
| 15 | 100014 169 | ||
| 16 | 100015 178 | ||
| 17 | 100016 121 | ||
| 18 | 100017 34 | ||
| 19 | 100018 24 | ||
| 20 | 100019 67 | ||
| 21 | 100020 325 | ||
| 22 | 100021 115 | ||
| 23 | 100022 67 | ||
| 24 | 100024 243 | ||
| 25 | 100025 82 | ||
| 26 | 100026 312 | ||
| 27 | 100027 142 | ||
| 28 | 100028 13 | ||
| 29 | 100029 161 | ||
| 30 | 100030 55 | ||
| 31 | 100031 264 | ||
| 32 | 100033 70 | ||
| 33 | 100036 117 | ||
| 34 | 100037 3 | ||
| 35 | 100038 194 | ||
| 36 | 100039 265 | ||
| 37 | 100041 308 | ||
| 38 | 100042 32 | ||
| 39 | 100043 149 | ||
| 40 | 100044 449 | ||
| 41 | 100045 164 | ||
| 42 | 100046 161 | ||
| 43 | 100047 376 | ||
| 44 | 100048 83 | ||
| 45 | 100049 59 | ||
| 46 | 100051 83 | ||
| 47 | 100052 319 | ||
| 48 | 100053 339 | ||
| 49 | 100056 236 | ||
| 50 | 100058 157 | ||
| 51 | 100059 77 | ||
| 52 | 100060 324 | ||
| 53 | 100062 407 | ||
| 54 | 100063 169 | ||
| 55 | 100064 51 | ||
| 56 | 100065 464 | ||
| 57 | 100066 156 | ||
| 58 | 100067 410 | ||
| 59 | 100068 41 | ||
| 60 | 100069 17 | ||
| 61 | 100070 132 | ||
| 62 | 100071 232 | ||
| 63 | 100072 29 | ||
| 64 | 100073 218 | ||
| 65 | 100074 320 | ||
| 66 | 100075 4 | ||
| 67 | 100076 22 | ||
| 68 | 100077 272 | ||
| 69 | 100079 139 | ||
| 70 | 100081 205 | ||
| 71 | 100084 116 | ||
| 72 | 100086 139 | ||
| 73 | 100087 245 | ||
| 74 | 100088 334 | ||
| 75 | 100089 192 | ||
| 76 | 100090 225 | ||
| 77 | 100091 411 | ||
| 78 | 100092 424 | ||
| 79 | 100093 230 | ||
| 80 | 100095 126 | ||
| 81 | 100096 262 | ||
| 82 | 100097 394 | ||
| 83 | 100099 287 | ||
diff --git a/test/112_h48map/h48map_tests.c b/test/112_h48map/h48map_tests.c new file mode 100644 index 0000000..ce8f657 --- /dev/null +++ b/test/112_h48map/h48map_tests.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | #define MAP_KEYSHIFT UINT64_C(40) | ||
| 4 | |||
| 5 | typedef struct { | ||
| 6 | uint64_t n; | ||
| 7 | uint64_t capacity; | ||
| 8 | uint64_t mod; | ||
| 9 | uint64_t *table; | ||
| 10 | } h48map_t; | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | uint64_t key; | ||
| 14 | uint64_t val; | ||
| 15 | } kvpair_t; | ||
| 16 | |||
| 17 | void h48map_create(h48map_t *, uint64_t, uint64_t); | ||
| 18 | void h48map_clear(h48map_t *); | ||
| 19 | void h48map_destroy(h48map_t *); | ||
| 20 | uint64_t h48map_lookup(h48map_t *, uint64_t); | ||
| 21 | void h48map_insertmin(h48map_t *, uint64_t, uint64_t); | ||
| 22 | uint64_t h48map_value(h48map_t *, uint64_t); | ||
| 23 | kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *); | ||
| 24 | |||
| 25 | char str[STRLENMAX]; | ||
| 26 | |||
| 27 | int compare(const void *x, const void *y) { | ||
| 28 | uint64_t a = ((kvpair_t *)x)->key; | ||
| 29 | uint64_t b = ((kvpair_t *)y)->key; | ||
| 30 | |||
| 31 | if (a > b) return 1; | ||
| 32 | if (a == b) return 0; | ||
| 33 | return -1; | ||
| 34 | } | ||
| 35 | |||
| 36 | uint64_t readl(void) { | ||
| 37 | fgets(str, STRLENMAX, stdin); | ||
| 38 | return atoll(str); | ||
| 39 | } | ||
| 40 | |||
| 41 | void run(void) { | ||
| 42 | h48map_t map; | ||
| 43 | uint64_t n, i, j, capacity, mod, x, y, v; | ||
| 44 | kvpair_t kv, *a, *b; | ||
| 45 | |||
| 46 | capacity = readl(); | ||
| 47 | mod = readl(); | ||
| 48 | n = readl(); | ||
| 49 | |||
| 50 | a = malloc(n * sizeof(kvpair_t)); | ||
| 51 | b = malloc(n * sizeof(kvpair_t)); | ||
| 52 | for (i = 0; i < n; i++) { | ||
| 53 | x = readl(); | ||
| 54 | y = readl(); | ||
| 55 | a[i] = (kvpair_t) { .key = x, .val = y }; | ||
| 56 | } | ||
| 57 | |||
| 58 | h48map_create(&map, capacity, mod); | ||
| 59 | for (i = 0; i < n; i++) | ||
| 60 | h48map_insertmin(&map, a[i].key, a[i].val); | ||
| 61 | |||
| 62 | i = 0; | ||
| 63 | for (kv = h48map_nextkvpair(&map, &i), j = 0; | ||
| 64 | i != map.capacity; | ||
| 65 | kv = h48map_nextkvpair(&map, &i) | ||
| 66 | ) { | ||
| 67 | b[j++] = kv; | ||
| 68 | } | ||
| 69 | qsort(b, j, sizeof(kvpair_t), compare); | ||
| 70 | |||
| 71 | printf("%" PRIu64 "\n", map.n); | ||
| 72 | for (i = 0; i < j; i++) | ||
| 73 | printf("%" PRIu64 " %" PRIu64 "\n", b[i].key, b[i].val); | ||
| 74 | if (map.n != j) | ||
| 75 | printf("Wrong number of elements: map->n = %" PRIu64 ", " | ||
| 76 | "but scan returns %" PRIu64 "\n", map.n, j); | ||
| 77 | for (i = 0; i < n; i++) { | ||
| 78 | v = h48map_value(&map, a[i].key); | ||
| 79 | if (v > a[i].val) | ||
| 80 | printf("Value for key %" PRId64 " is larger than " | ||
| 81 | "expected (%" PRIu64 " > %" PRIu64 ")\n", | ||
| 82 | a[i].key, v, a[i].val); | ||
| 83 | } | ||
| 84 | |||
| 85 | h48map_destroy(&map); | ||
| 86 | free(a); | ||
| 87 | free(b); | ||
| 88 | } | ||
diff --git a/test/112_h48set/00_small.in b/test/112_h48set/00_small.in deleted file mode 100644 index d788d5b..0000000 --- a/test/112_h48set/00_small.in +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | 11 | ||
| 2 | 7 | ||
| 3 | 3 | ||
| 4 | 34 | ||
| 5 | 45 | ||
| 6 | 34 | ||
diff --git a/test/112_h48set/00_small.out b/test/112_h48set/00_small.out deleted file mode 100644 index 29c08e5..0000000 --- a/test/112_h48set/00_small.out +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | 2 | ||
| 2 | 34 | ||
| 3 | 45 | ||
diff --git a/test/112_h48set/01_large.out b/test/112_h48set/01_large.out deleted file mode 100644 index 6632336..0000000 --- a/test/112_h48set/01_large.out +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | 82 | ||
| 2 | 100000 | ||
| 3 | 100001 | ||
| 4 | 100002 | ||
| 5 | 100004 | ||
| 6 | 100005 | ||
| 7 | 100006 | ||
| 8 | 100007 | ||
| 9 | 100008 | ||
| 10 | 100009 | ||
| 11 | 100010 | ||
| 12 | 100011 | ||
| 13 | 100012 | ||
| 14 | 100013 | ||
| 15 | 100014 | ||
| 16 | 100015 | ||
| 17 | 100016 | ||
| 18 | 100017 | ||
| 19 | 100018 | ||
| 20 | 100019 | ||
| 21 | 100020 | ||
| 22 | 100021 | ||
| 23 | 100022 | ||
| 24 | 100024 | ||
| 25 | 100025 | ||
| 26 | 100026 | ||
| 27 | 100027 | ||
| 28 | 100028 | ||
| 29 | 100029 | ||
| 30 | 100030 | ||
| 31 | 100031 | ||
| 32 | 100033 | ||
| 33 | 100036 | ||
| 34 | 100037 | ||
| 35 | 100038 | ||
| 36 | 100039 | ||
| 37 | 100041 | ||
| 38 | 100042 | ||
| 39 | 100043 | ||
| 40 | 100044 | ||
| 41 | 100045 | ||
| 42 | 100046 | ||
| 43 | 100047 | ||
| 44 | 100048 | ||
| 45 | 100049 | ||
| 46 | 100051 | ||
| 47 | 100052 | ||
| 48 | 100053 | ||
| 49 | 100056 | ||
| 50 | 100058 | ||
| 51 | 100059 | ||
| 52 | 100060 | ||
| 53 | 100062 | ||
| 54 | 100063 | ||
| 55 | 100064 | ||
| 56 | 100065 | ||
| 57 | 100066 | ||
| 58 | 100067 | ||
| 59 | 100068 | ||
| 60 | 100069 | ||
| 61 | 100070 | ||
| 62 | 100071 | ||
| 63 | 100072 | ||
| 64 | 100073 | ||
| 65 | 100074 | ||
| 66 | 100075 | ||
| 67 | 100076 | ||
| 68 | 100077 | ||
| 69 | 100079 | ||
| 70 | 100081 | ||
| 71 | 100084 | ||
| 72 | 100086 | ||
| 73 | 100087 | ||
| 74 | 100088 | ||
| 75 | 100089 | ||
| 76 | 100090 | ||
| 77 | 100091 | ||
| 78 | 100092 | ||
| 79 | 100093 | ||
| 80 | 100095 | ||
| 81 | 100096 | ||
| 82 | 100097 | ||
| 83 | 100099 | ||
diff --git a/test/112_h48set/h48set_tests.c b/test/112_h48set/h48set_tests.c deleted file mode 100644 index d9310a9..0000000 --- a/test/112_h48set/h48set_tests.c +++ /dev/null | |||
| @@ -1,64 +0,0 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | char str[STRLENMAX]; | ||
| 4 | |||
| 5 | typedef struct { | ||
| 6 | int64_t n; | ||
| 7 | int64_t capacity; | ||
| 8 | int64_t mod; | ||
| 9 | int64_t *table; | ||
| 10 | } h48set_t; | ||
| 11 | |||
| 12 | void h48set_create(h48set_t *, int64_t, int64_t); | ||
| 13 | void h48set_clear(h48set_t *); | ||
| 14 | void h48set_destroy(h48set_t *); | ||
| 15 | int64_t h48set_lookup(h48set_t *, int64_t); | ||
| 16 | void h48set_insert(h48set_t *, int64_t); | ||
| 17 | bool h48set_contains(h48set_t *, int64_t); | ||
| 18 | int64_t h48set_save(h48set_t *, int64_t *); | ||
| 19 | |||
| 20 | int compare(const void *x, const void *y) { | ||
| 21 | int64_t a = *(int64_t *)x; | ||
| 22 | int64_t b = *(int64_t *)y; | ||
| 23 | |||
| 24 | if (a > b) return 1; | ||
| 25 | if (a == b) return 0; | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | |||
| 29 | int64_t readl(void) { | ||
| 30 | fgets(str, STRLENMAX, stdin); | ||
| 31 | return atoll(str); | ||
| 32 | } | ||
| 33 | |||
| 34 | void run(void) { | ||
| 35 | h48set_t set; | ||
| 36 | int64_t n, i, k, capacity, mod, *a, *b; | ||
| 37 | |||
| 38 | capacity = readl(); | ||
| 39 | mod = readl(); | ||
| 40 | n = readl(); | ||
| 41 | |||
| 42 | a = malloc(n * sizeof(int64_t)); | ||
| 43 | b = malloc(n * sizeof(int64_t)); | ||
| 44 | for (i = 0; i < n; i++) | ||
| 45 | a[i] = readl(); | ||
| 46 | |||
| 47 | h48set_create(&set, capacity, mod); | ||
| 48 | for (i = 0; i < n; i++) | ||
| 49 | h48set_insert(&set, a[i]); | ||
| 50 | |||
| 51 | k = h48set_save(&set, b); | ||
| 52 | qsort(b, k, sizeof(int64_t), compare); | ||
| 53 | |||
| 54 | printf("%" PRId64 "\n", k); | ||
| 55 | for (i = 0; i < k; i++) | ||
| 56 | printf("%" PRId64 "\n", b[i]); | ||
| 57 | for (i = 0; i < n; i++) | ||
| 58 | if (!h48set_contains(&set, a[i])) | ||
| 59 | printf("Set does not contain %" PRId64 "\n", a[i]); | ||
| 60 | |||
| 61 | h48set_destroy(&set); | ||
| 62 | free(a); | ||
| 63 | free(b); | ||
| 64 | } | ||
