summaryrefslogtreecommitdiff
path: root/src/tuple.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tuple.h')
-rw-r--r--src/tuple.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/tuple.h b/src/tuple.h
new file mode 100644
index 0000000..3c3f0fa
--- /dev/null
+++ b/src/tuple.h
@@ -0,0 +1,116 @@
+#ifndef TUPLE_H
+#define TUPLE_H
+#include "util.h"
+#include "pair.h"
+
+/* This file implements the tuples that we need. A tuple is an array
+ of arrays of arrays, ..., ad infinitum.
+
+ Since the lengths of each layer of the arrays are different, but
+ uniform within each layer, we store the lengths in an array at the
+ top level. So there are two kinds of data types: one with an array
+ of lengths and the other without. */
+
+#define TUP(N) typedef struct PASTER(tuple, N, _s) PASTER(tuple, N,)
+#define LTUP(N) typedef struct PASTER(luple, N, _s) PASTER(luple, N,)
+
+#define LONSTRUCT(N) PASTER(luple, N,) *PASTER(new, _luple, N) \
+ (NUM *len)
+
+#define LESTRUCT(N) void PASTER(destroy_luple, N,) \
+ (PASTER(luple, N,) *tup)
+
+#define ADDL(N) BOOL PASTER(add_to_luple, N,) \
+ (PASTER(luple, N,) *lup, PASTER(pair, N,) label, \
+ NUM val)
+
+#define INDEXL(N) HP_ATTR \
+ NUM *PASTER(luple, N, _find) \
+ (PASTER(luple, N,) *lup, PASTER(pair, N,) label)
+
+#define LENTHL(N) P_ATTR NUM *PASTER(luple, N, _len) \
+ (PASTER(luple, N,) *lup)
+
+typedef struct PASTER(tuple, 1, _s) PASTER(tuple, 1,);
+
+TUP(2);
+TUP(3);
+TUP(4);
+TUP(5);
+TUP(6);
+
+LTUP(2);
+LTUP(3);
+LTUP(4);
+LTUP(5);
+LTUP(6);
+
+tuple4 *new_tuple4();
+
+LONSTRUCT(2);
+LONSTRUCT(3);
+LONSTRUCT(4);
+LONSTRUCT(5);
+LONSTRUCT(6);
+
+void destroy_tuple4(tuple4 tup, NUM *len);
+
+LESTRUCT(2);
+LESTRUCT(3);
+LESTRUCT(4);
+LESTRUCT(5);
+LESTRUCT(6);
+
+ADDL(2);
+ADDL(3);
+ADDL(4);
+ADDL(5);
+ADDL(6);
+
+H_ATTR BOOL add_to_luple6_pt_2(luple6 *lup, pair2 label);
+
+INDEXL(2);
+INDEXL(3);
+INDEXL(4);
+INDEXL(5);
+INDEXL(6);
+
+LENTHL(2);
+LENTHL(3);
+LENTHL(4);
+LENTHL(5);
+LENTHL(6);
+
+HP_ATTR BOOL luple3_pf_2(luple3 *lup, pair2 label);
+HP_ATTR BOOL luple5_pf_3(luple5 *lup, pair3 label);
+HP_ATTR BOOL luple6_pf_2(luple6 *lup, pair2 label);
+
+typedef void (* map_pair3_t) (pair3 label);
+typedef void (* map_pair5_t) (pair5 label);
+typedef void (* map_pair6_t) (pair6 label);
+
+H_ATTR void luple3_map_2(luple3 *lup, pair2 label, map_pair3_t fn);
+
+/* H_ATTR void tuple5_map_3(tuple5 *lup, pair3 label, map_pair5_t fn); */
+
+H_ATTR void luple5_map_3(luple5 *lup, pair3 label, map_pair5_t fn);
+
+H_ATTR void luple5_free_1(luple5 *lup, NUM label);
+
+/* MAX bounds the last coordinate, i.e. the W coordinate. If -1 then
+ there is no bound. */
+H_ATTR void luple6_map_2(luple6 *lup, pair2 label,
+ NUM max, map_pair6_t fn);
+
+H_ATTR void luple6_map_5(luple6 *tup, pair5 label, map_pair6_t fn);
+
+#undef LONSTRUCT
+#undef LESTRUCT
+#undef LTUP
+#undef TUP
+#undef ADDL
+#undef INDEXL
+#undef INDEXPL
+#undef LENTHL
+
+#endif