aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-13 08:03:20 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-13 08:03:20 +0200
commit3b313daec1614d8a3288b8e20a06dc912a59bda8 (patch)
tree9b4ade371c2c021c905f8abe38503f7f910d3764 /src
parent4abb81c230bfcd599ccceb2b1bcbdcadbd859537 (diff)
downloadnissy-core-3b313daec1614d8a3288b8e20a06dc912a59bda8.tar.gz
nissy-core-3b313daec1614d8a3288b8e20a06dc912a59bda8.zip
Added a set implementation for h48 table generation
Diffstat (limited to 'src')
-rw-r--r--src/solve_h48.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/solve_h48.h b/src/solve_h48.h
index 5f99d15..4bf9f78 100644
--- a/src/solve_h48.h
+++ b/src/solve_h48.h
@@ -24,6 +24,13 @@
24#define MAX_SOLUTION_LENGTH 20 24#define MAX_SOLUTION_LENGTH 20
25 25
26typedef struct { 26typedef struct {
27 int64_t n;
28 int64_t capacity;
29 int64_t mod;
30 int64_t *table;
31} h48set_t;
32
33typedef struct {
27 cube_t cube; 34 cube_t cube;
28 uint8_t depth; 35 uint8_t depth;
29 uint8_t maxdepth; 36 uint8_t maxdepth;
@@ -66,6 +73,13 @@ typedef struct {
66 char *s; 73 char *s;
67} dfsarg_solveh48stats_t; 74} dfsarg_solveh48stats_t;
68 75
76_static void h48set_create(h48set_t *, int64_t, int64_t);
77_static void h48set_clear(h48set_t *);
78_static void h48set_destroy(h48set_t *);
79_static_inline int64_t h48set_lookup(h48set_t *, int64_t);
80_static_inline void h48set_insert(h48set_t *, int64_t);
81_static_inline bool h48set_contains(h48set_t *, int64_t);
82
69_static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t); 83_static_inline int64_t coord_h48(cube_t, const uint32_t *, uint8_t);
70_static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t); 84_static_inline int64_t coord_h48_edges(cube_t, int64_t, uint8_t, uint8_t);
71_static_inline cube_t invcoord_h48(int64_t, const cube_t *, uint8_t); 85_static_inline cube_t invcoord_h48(int64_t, const cube_t *, uint8_t);
@@ -90,6 +104,69 @@ _static int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, const void *,
90_static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); 104_static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *);
91_static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); 105_static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]);
92 106
107_static void
108h48set_create(h48set_t *set, int64_t capacity, int64_t mod)
109{
110 set->capacity = capacity;
111 set->mod = mod;
112
113 set->table = malloc(set->capacity * sizeof(int64_t));
114 h48set_clear(set);
115}
116
117_static void
118h48set_clear(h48set_t *set)
119{
120 int64_t i;
121
122 for (i = 0; i < set->capacity; i++)
123 set->table[i] = -1;
124
125 set->n = 0;
126}
127
128_static void
129h48set_destroy(h48set_t *set)
130{
131 free(set->table);
132}
133
134/* Returns the index in where x should be inserted, or -1 if x is in the set */
135_static_inline int64_t
136h48set_lookup(h48set_t *set, int64_t x)
137{
138 int64_t hash, i;
139
140 hash = ((x % set->capacity) * set->mod) % set->capacity;
141 for (i = hash; set->table[i] != -1; i = (i+1) % set->capacity)
142 if (set->table[i] == x)
143 return -1;
144
145 return i;
146}
147
148_static_inline void
149h48set_insert(h48set_t *set, int64_t x)
150{
151 int64_t i;
152
153 i = h48set_lookup(set, x);
154 if (i != -1) {
155 set->table[i] = x;
156 set->n++;
157 }
158}
159
160_static_inline bool
161h48set_contains(h48set_t *set, int64_t x)
162{
163 int64_t i;
164
165 i = h48set_lookup(set, x);
166
167 return i == -1;
168}
169
93_static_inline int64_t 170_static_inline int64_t
94coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h) 171coord_h48(cube_t c, const uint32_t *cocsepdata, uint8_t h)
95{ 172{

Generated with cgit - Back to sebastiano.tronto.net