aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/map.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-03-25 18:35:47 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-03-25 18:35:47 +0100
commit56048d13b73ec6e6a9c59d62e82f41e69a3994bd (patch)
tree49fc5d50e739a399897425756c08a73ba5924ddb /src/solvers/h48/map.h
parent0f4931c8de298b0f97aba1757c9538f48adb30c6 (diff)
downloadnissy-core-56048d13b73ec6e6a9c59d62e82f41e69a3994bd.tar.gz
nissy-core-56048d13b73ec6e6a9c59d62e82f41e69a3994bd.zip
More safety with pointers using VLA function parameters
Diffstat (limited to 'src/solvers/h48/map.h')
-rw-r--r--src/solvers/h48/map.h31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/solvers/h48/map.h b/src/solvers/h48/map.h
index e6903ce..7718794 100644
--- a/src/solvers/h48/map.h
+++ b/src/solvers/h48/map.h
@@ -1,16 +1,13 @@
1/* Type definitions and macros are in a separate file for easier testing */ 1STATIC void h48map_create(h48map_t [static 1], uint64_t, uint64_t);
2#include "map_types_macros.h" 2STATIC void h48map_clear(h48map_t [static 1]);
3 3STATIC void h48map_destroy(h48map_t [static 1]);
4STATIC void h48map_create(h48map_t *, uint64_t, uint64_t); 4STATIC uint64_t h48map_lookup(h48map_t [static 1], uint64_t);
5STATIC void h48map_clear(h48map_t *); 5STATIC void h48map_insertmin(h48map_t [static 1], uint64_t, uint64_t);
6STATIC void h48map_destroy(h48map_t *); 6STATIC uint64_t h48map_value(h48map_t [static 1], uint64_t);
7STATIC uint64_t h48map_lookup(h48map_t *, uint64_t); 7STATIC kvpair_t h48map_nextkvpair(h48map_t [static 1], uint64_t [static 1]);
8STATIC void h48map_insertmin(h48map_t *, uint64_t, uint64_t);
9STATIC uint64_t h48map_value(h48map_t *, uint64_t);
10STATIC kvpair_t h48map_nextkvpair(h48map_t *, uint64_t *);
11 8
12STATIC void 9STATIC void
13h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer) 10h48map_create(h48map_t map[static 1], uint64_t capacity, uint64_t randomizer)
14{ 11{
15 map->capacity = capacity; 12 map->capacity = capacity;
16 map->randomizer = randomizer; 13 map->randomizer = randomizer;
@@ -20,20 +17,20 @@ h48map_create(h48map_t *map, uint64_t capacity, uint64_t randomizer)
20} 17}
21 18
22STATIC void 19STATIC void
23h48map_clear(h48map_t *map) 20h48map_clear(h48map_t map[static 1])
24{ 21{
25 memset(map->table, 0xFF, map->capacity * sizeof(uint64_t)); 22 memset(map->table, 0xFF, map->capacity * sizeof(uint64_t));
26 map->n = 0; 23 map->n = 0;
27} 24}
28 25
29STATIC void 26STATIC void
30h48map_destroy(h48map_t *map) 27h48map_destroy(h48map_t map[static 1])
31{ 28{
32 free(map->table); 29 free(map->table);
33} 30}
34 31
35STATIC_INLINE uint64_t 32STATIC_INLINE uint64_t
36h48map_lookup(h48map_t *map, uint64_t x) 33h48map_lookup(h48map_t map[static 1], uint64_t x)
37{ 34{
38 uint64_t hash, i; 35 uint64_t hash, i;
39 36
@@ -47,7 +44,7 @@ h48map_lookup(h48map_t *map, uint64_t x)
47} 44}
48 45
49STATIC_INLINE void 46STATIC_INLINE void
50h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val) 47h48map_insertmin(h48map_t map[static 1], uint64_t key, uint64_t val)
51{ 48{
52 uint64_t i, oldval, min; 49 uint64_t i, oldval, min;
53 50
@@ -60,13 +57,13 @@ h48map_insertmin(h48map_t *map, uint64_t key, uint64_t val)
60} 57}
61 58
62STATIC_INLINE uint64_t 59STATIC_INLINE uint64_t
63h48map_value(h48map_t *map, uint64_t key) 60h48map_value(h48map_t map[static 1], uint64_t key)
64{ 61{
65 return map->table[h48map_lookup(map, key)] >> MAP_KEYSHIFT; 62 return map->table[h48map_lookup(map, key)] >> MAP_KEYSHIFT;
66} 63}
67 64
68STATIC kvpair_t 65STATIC kvpair_t
69h48map_nextkvpair(h48map_t *map, uint64_t *p) 66h48map_nextkvpair(h48map_t map[static 1], uint64_t p[static 1])
70{ 67{
71 kvpair_t kv; 68 kvpair_t kv;
72 uint64_t pair; 69 uint64_t pair;

Generated with cgit - Back to sebastiano.tronto.net