summaryrefslogtreecommitdiff
path: root/src/pair.h
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-02-05 17:30:11 +0800
committerJSDurand <mmemmew@gmail.com>2022-02-05 17:30:11 +0800
commit510b10b96b546fcc6c6b6be85050305ddd192a41 (patch)
tree997d6c3f2c0a1ad6e27127d54a94655527e57864 /src/pair.h
parent3fb5430080199a6d92a63f8259fe4a88df9b83ba (diff)
replace some hash table usage by tuples
Previously I used hash tables, which consume too much memory. Now the critical parts are replaced by a new hand-written library called "tuple.h". Now we can easily parse larger inputs. I haven't tested its limits, though.
Diffstat (limited to 'src/pair.h')
-rw-r--r--src/pair.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/pair.h b/src/pair.h
new file mode 100644
index 0000000..baae9f5
--- /dev/null
+++ b/src/pair.h
@@ -0,0 +1,57 @@
+#ifndef PAIR_H
+#define PAIR_H
+#include "util.h"
+
+/* This header contains struct definitions of some pairs. */
+
+/* I probably should have named the fields by numbers, such as x1, x2,
+ etc, so that we can recursively declare these structs by macros.
+ But it is not worth the trouble to rewrite this I guess. */
+
+typedef NUM pair1;
+
+struct pair2_s { NUM x; NUM y; };
+
+typedef struct pair2_s pair2;
+
+struct pair3_s { NUM x; NUM y; NUM z; };
+
+typedef struct pair3_s pair3;
+
+struct pair4_s { NUM x; NUM y; NUM z; NUM u; };
+
+typedef struct pair4_s pair4;
+
+struct pair5_s { NUM x; NUM y; NUM z; NUM u; NUM v; };
+
+typedef struct pair5_s pair5;
+
+struct pair6_s { NUM x; NUM y; NUM z; NUM u; NUM v; NUM w; };
+
+typedef struct pair6_s pair6;
+
+#define COPY_PAIR1(DEST, SOUR) do { \
+ DEST.x = SOUR.y; \
+ } while (0)
+
+#define COPY_PAIR2(DEST, SOUR) do { \
+ COPY_PAIR1(DEST, SOUR); \
+ DEST.y = SOUR.z; \
+ } while (0)
+
+#define COPY_PAIR3(DEST, SOUR) do { \
+ COPY_PAIR2(DEST, SOUR); \
+ DEST.z = SOUR.u; \
+ } while (0)
+
+#define COPY_PAIR4(DEST, SOUR) do { \
+ COPY_PAIR3(DEST, SOUR); \
+ DEST.u = SOUR.v; \
+ } while (0)
+
+#define COPY_PAIR5(DEST, SOUR) do { \
+ COPY_PAIR4(DEST, SOUR); \
+ DEST.v = SOUR.w; \
+ } while (0)
+
+#endif