diff options
| -rw-r--r-- | src/solve_h48.h | 13 | ||||
| -rw-r--r-- | test/104_h48set/h48set_tests.c | 29 |
2 files changed, 25 insertions, 17 deletions
diff --git a/src/solve_h48.h b/src/solve_h48.h index 4bf9f78..bfcf585 100644 --- a/src/solve_h48.h +++ b/src/solve_h48.h | |||
| @@ -79,6 +79,7 @@ _static void h48set_destroy(h48set_t *); | |||
| 79 | _static_inline int64_t h48set_lookup(h48set_t *, int64_t); | 79 | _static_inline int64_t h48set_lookup(h48set_t *, int64_t); |
| 80 | _static_inline void h48set_insert(h48set_t *, int64_t); | 80 | _static_inline void h48set_insert(h48set_t *, int64_t); |
| 81 | _static_inline bool h48set_contains(h48set_t *, int64_t); | 81 | _static_inline bool h48set_contains(h48set_t *, int64_t); |
| 82 | _static inline int64_t h48set_save(h48set_t *, int64_t *); | ||
| 82 | 83 | ||
| 83 | _static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t); | 84 | _static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t); |
| 84 | _static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); | 85 | _static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); |
| @@ -167,6 +168,18 @@ h48set_contains(h48set_t *set, int64_t x) | |||
| 167 | return i == -1; | 168 | return i == -1; |
| 168 | } | 169 | } |
| 169 | 170 | ||
| 171 | _static int64_t | ||
| 172 | h48set_save(h48set_t *set, int64_t *a) | ||
| 173 | { | ||
| 174 | int64_t i, j; | ||
| 175 | |||
| 176 | for (i = 0, j = 0; i < set->capacity; i++) | ||
| 177 | if (set->table[i] != -1) | ||
| 178 | a[j++] = set->table[i]; | ||
| 179 | |||
| 180 | return j; | ||
| 181 | } | ||
| 182 | |||
| 170 | _static_inline int64_t | 183 | _static_inline int64_t |
| 171 | coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) | 184 | coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) |
| 172 | { | 185 | { |
diff --git a/test/104_h48set/h48set_tests.c b/test/104_h48set/h48set_tests.c index 97811da..d9310a9 100644 --- a/test/104_h48set/h48set_tests.c +++ b/test/104_h48set/h48set_tests.c | |||
| @@ -15,6 +15,7 @@ void h48set_destroy(h48set_t *); | |||
| 15 | int64_t h48set_lookup(h48set_t *, int64_t); | 15 | int64_t h48set_lookup(h48set_t *, int64_t); |
| 16 | void h48set_insert(h48set_t *, int64_t); | 16 | void h48set_insert(h48set_t *, int64_t); |
| 17 | bool h48set_contains(h48set_t *, int64_t); | 17 | bool h48set_contains(h48set_t *, int64_t); |
| 18 | int64_t h48set_save(h48set_t *, int64_t *); | ||
| 18 | 19 | ||
| 19 | int compare(const void *x, const void *y) { | 20 | int compare(const void *x, const void *y) { |
| 20 | int64_t a = *(int64_t *)x; | 21 | int64_t a = *(int64_t *)x; |
| @@ -31,39 +32,33 @@ int64_t readl(void) { | |||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 33 | void run(void) { | 34 | void run(void) { |
| 34 | bool f; | ||
| 35 | h48set_t set; | 35 | h48set_t set; |
| 36 | int64_t n, i, j, capacity, mod, *a, u; | 36 | int64_t n, i, k, capacity, mod, *a, *b; |
| 37 | 37 | ||
| 38 | capacity = readl(); | 38 | capacity = readl(); |
| 39 | mod = readl(); | 39 | mod = readl(); |
| 40 | n = readl(); | 40 | n = readl(); |
| 41 | 41 | ||
| 42 | a = malloc(n * sizeof(int64_t)); | 42 | a = malloc(n * sizeof(int64_t)); |
| 43 | b = malloc(n * sizeof(int64_t)); | ||
| 43 | for (i = 0; i < n; i++) | 44 | for (i = 0; i < n; i++) |
| 44 | a[i] = readl(); | 45 | a[i] = readl(); |
| 45 | 46 | ||
| 46 | /* Count unique elements */ | ||
| 47 | u = 0; | ||
| 48 | for (i = 0; i < n; i++) { | ||
| 49 | for (j = 0, f = true; j < i; j++) | ||
| 50 | f = f && a[i] != a[j]; | ||
| 51 | u += f; | ||
| 52 | } | ||
| 53 | |||
| 54 | h48set_create(&set, capacity, mod); | 47 | h48set_create(&set, capacity, mod); |
| 55 | for (i = 0; i < n; i++) | 48 | for (i = 0; i < n; i++) |
| 56 | h48set_insert(&set, a[i]); | 49 | h48set_insert(&set, a[i]); |
| 57 | 50 | ||
| 58 | for (i = 0, j = 0; i < set.capacity; i++) | 51 | k = h48set_save(&set, b); |
| 59 | if (set.table[i] != -1) | 52 | qsort(b, k, sizeof(int64_t), compare); |
| 60 | a[j++] = set.table[i]; | ||
| 61 | qsort(a, j, sizeof(int64_t), compare); | ||
| 62 | 53 | ||
| 63 | printf("%" PRId64 "\n", set.n); | 54 | printf("%" PRId64 "\n", k); |
| 64 | for (i = 0; i < j; i++) | 55 | for (i = 0; i < k; i++) |
| 65 | printf("%" PRId64 "\n", a[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]); | ||
| 66 | 60 | ||
| 67 | h48set_destroy(&set); | 61 | h48set_destroy(&set); |
| 68 | free(a); | 62 | free(a); |
| 63 | free(b); | ||
| 69 | } | 64 | } |
