aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/solvers/solvers.h1
-rw-r--r--src/solvers/tables.h93
2 files changed, 94 insertions, 0 deletions
diff --git a/src/solvers/solvers.h b/src/solvers/solvers.h
index 66c9b27..00a28c1 100644
--- a/src/solvers/solvers.h
+++ b/src/solvers/solvers.h
@@ -1,2 +1,3 @@
1#include "tables.h"
1#include "generic/generic.h" 2#include "generic/generic.h"
2#include "h48/h48.h" 3#include "h48/h48.h"
diff --git a/src/solvers/tables.h b/src/solvers/tables.h
new file mode 100644
index 0000000..be0209f
--- /dev/null
+++ b/src/solvers/tables.h
@@ -0,0 +1,93 @@
1#define OFFSET(B, K) (((uint8_t *)B) + K)
2#define INFOSIZE 512
3#define INFO_OFFSET_SOLVER 0
4#define INFO_SOLVER_STRLEN 20
5#define INFO_OFFSET_INFOSIZE INFO_SOLVER_STRLEN
6#define INFO_OFFSET_FULLSIZE (INFO_OFFSET_INFOSIZE + sizeof(uint64_t))
7#define INFO_OFFSET_HASH (INFO_OFFSET_FULLSIZE + sizeof(uint64_t))
8#define INFO_OFFSET_ENTRIES (INFO_OFFSET_HASH + sizeof(uint64_t))
9#define INFO_OFFSET_BITS (INFO_OFFSET_ENTRIES + sizeof(uint64_t))
10#define INFO_OFFSET_BASE (INFO_OFFSET_BITS + sizeof(uint8_t))
11#define INFO_OFFSET_MAXVALUE (INFO_OFFSET_BASE + sizeof(uint8_t))
12#define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_MAXVALUE + sizeof(uint8_t))
13#define INFO_DISTRIBUTION_LEN 21
14
15typedef struct {
16 char solver[INFO_SOLVER_STRLEN];
17 uint64_t infosize;
18 uint64_t fullsize;
19 uint64_t hash;
20 uint64_t entries;
21 uint8_t bits;
22 uint8_t base;
23 uint8_t maxvalue;
24 uint64_t distribution[INFO_DISTRIBUTION_LEN];
25} tableinfo_t;
26
27STATIC bool readtableinfo(const void *, tableinfo_t *);
28STATIC bool writetableinfo(const tableinfo_t *, void *);
29
30STATIC bool
31readtableinfo(const void *buf, tableinfo_t *info)
32{
33 if (buf == NULL) {
34 LOG("Error reading table: buffer in NULL\n");
35 return false;
36 }
37
38 if (info == NULL) {
39 LOG("Error reading table info: info struct is NULL\n");
40 return false;
41 }
42
43 memcpy(info->solver, OFFSET(buf, INFO_OFFSET_SOLVER),
44 INFO_SOLVER_STRLEN);
45 info->infosize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE);
46 info->fullsize = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE);
47 info->hash = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_HASH);
48 info->entries = *(const uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES);
49 info->bits = *OFFSET(buf, INFO_OFFSET_BITS);
50 info->base = *OFFSET(buf, INFO_OFFSET_BASE);
51 info->maxvalue = *OFFSET(buf, INFO_OFFSET_MAXVALUE);
52 memcpy(info->distribution, OFFSET(buf, INFO_OFFSET_DISTRIBUTION),
53 INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
54
55 return true;
56}
57
58STATIC bool
59writetableinfo(const tableinfo_t *info, void *buf)
60{
61 int i;
62
63 if (buf == NULL) {
64 LOG("Error reading table: buffer in NULL\n");
65 return false;
66 }
67
68 if (info == NULL) {
69 LOG("Error writing table info: provided info is NULL\n");
70 return false;
71 }
72
73 memcpy(OFFSET(buf, INFO_OFFSET_SOLVER), info->solver,
74 INFO_SOLVER_STRLEN);
75
76 /* Zeroing all chars after the end of the string, for consistency */
77 for (i = 1; i < INFO_SOLVER_STRLEN; i++)
78 if (*OFFSET(buf, i) == 0)
79 *OFFSET(buf, i) = 0;
80
81 *(uint64_t *)OFFSET(buf, INFO_OFFSET_INFOSIZE) = info->infosize;
82 *(uint64_t *)OFFSET(buf, INFO_OFFSET_FULLSIZE) = info->fullsize;
83 *(uint64_t *)OFFSET(buf, INFO_OFFSET_HASH) = info->hash;
84 *(uint64_t *)OFFSET(buf, INFO_OFFSET_ENTRIES) = info->entries;
85 *OFFSET(buf, INFO_OFFSET_BITS) = info->bits;
86 *OFFSET(buf, INFO_OFFSET_BASE) = info->base;
87 *OFFSET(buf, INFO_OFFSET_MAXVALUE) = info->maxvalue;
88
89 memcpy(OFFSET(buf, INFO_OFFSET_DISTRIBUTION), info->distribution,
90 INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
91
92 return true;
93}

Generated with cgit - Back to sebastiano.tronto.net