aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.h
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-12 12:07:17 +0200
committerlemon <lsof@mailbox.org>2023-06-12 12:10:47 +0200
commit984b74da895d7155f68434be9cc9b6d49a77abec (patch)
treef8748466b274abd172a1491a6b45cb8dcbfe7d32 /common.h
parent1139df03b0edbf08deb9aa26ade3776be3c1e180 (diff)
register renaming and such
Diffstat (limited to 'common.h')
-rw-r--r--common.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/common.h b/common.h
index e31d48b..ee6dee6 100644
--- a/common.h
+++ b/common.h
@@ -339,6 +339,29 @@ struct bitset { uvlong u; };
enum { BSNBIT = 8 * sizeof(uvlong) };
#define BSSIZE(nbit) ((nbit) / BSNBIT + ((nbit) % BSNBIT != 0))
+struct imapbase { short *k; struct bitset *bs; uint n, N; };
+/* map of short -> T */
+#define imap_of(T) struct { T *v; int tmp; struct imapbase mb; }
+void imap_init_(struct imapbase *, void **v, uint vsiz, uint N);
+int imap_get_(struct imapbase *, short k);
+int imap_set_(struct imapbase *, void **v, uint vsiz, short k);
+#define imap_free(m) (free((m)->mb.k), memset((m), 0, sizeof *(m)))
+#define imap_init(m, N) (imap_free(m), imap_init_(&(m)->mb, (void **)&(m)->v, sizeof*(m)->v, (N))
+#define imap_get(m, k) (((m)->tmp = imap_get_(&(m)->mb, k)) < 0 ? NULL : &(m)->v[(m)->tmp])
+#define imap_set(m, k, x) ((m)->tmp = imap_set_(&(m)->mb, (void **)&(m)->v, sizeof*(m)->v, k), \
+ (m)->v[(m)->tmp] = (x))
+
+struct pmapbase { void **k; uint n, N; };
+/* map of non-null ptr -> T */
+#define pmap_of(T) struct { T *v; int tmp; struct imapbase mb; }
+void pmap_init_(struct pmapbase *, void **v, uint vsiz, uint N);
+int pmap_get_(struct pmapbase *, void *k);
+int pmap_set_(struct pmapbase *, void **v, uint vsiz, void *k);
+#define pmap_free(m) (free((m)->mb.k), memset((m), 0, sizeof *(m)))
+#define pmap_init(m, N) (pmap_free(m), pmap_init_(&(m)->mb, (void **)&(m)->v, sizeof*(m)->v, (N))
+#define pmap_get(m, k) (((m)->tmp = pmap_get_(&(m)->mb, k)) < 0 ? NULL : &(m)->v[(m)->tmp])
+#define pmap_set(m, k, x) ((m)->v[pmap_set_(&(m)->mb, (void **)&(m)->v, sizeof*(m)->v, k)] = (x))
+
static inline bool
bstest(const struct bitset *bs, uint i)
{