From 27bef1109d733733b9ebb989ef905e2f072f1619 Mon Sep 17 00:00:00 2001 From: Zander Thannhauser Date: Sun, 15 Jun 2025 19:45:05 -0500 Subject: [PATCH] instead of sparse-lists, why not boolean arrays? --- main.c | 28 +-------- spikes/boolean-array-or-2.c | 0 spikes/boolean-array.c | 97 ++++++++++++++++++++++++++++++ spikes/sorted-sparse-list-remove.c | 5 ++ 4 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 spikes/boolean-array-or-2.c create mode 100644 spikes/boolean-array.c create mode 100644 spikes/sorted-sparse-list-remove.c diff --git a/main.c b/main.c index bfcfa16..e6f76e0 100644 --- a/main.c +++ b/main.c @@ -531,24 +531,12 @@ void calculate_simplifications(void) if (done.headtails[head] < index) { if (prevhead == -1) - { - assert(done.headtails[head] == head); - done.next[head] = index; - } else - { - int tophalftail = done.headtails[prevhead - 1]; - - assert(tophalftail != -1); - - done.next[tophalftail] = index; - } + done.next[tophalftail] = done.headtails[prevhead - 1]; } else - { done.head = index; - } int n = ~index & M; int tail = index & 1 ? index : index | (n & -n), prevtail = -1; @@ -563,21 +551,9 @@ void calculate_simplifications(void) if (index < done.headtails[tail]) { if (prevtail == -1) - { - assert(done.headtails[tail] == tail); - - assert(done.in[tail]); - done.next[index] = tail; - } else - { - int bottomhalfhead = done.headtails[prevtail + 1]; - - assert(bottomhalfhead != -1); - - done.next[index] = bottomhalfhead; - } + done.next[index] = done.headtails[prevtail + 1]; } else { diff --git a/spikes/boolean-array-or-2.c b/spikes/boolean-array-or-2.c new file mode 100644 index 0000000..e69de29 diff --git a/spikes/boolean-array.c b/spikes/boolean-array.c new file mode 100644 index 0000000..04457c6 --- /dev/null +++ b/spikes/boolean-array.c @@ -0,0 +1,97 @@ + +#include +#include +#include + +#define N (256) + +#define M (255) + +struct boolist { + int data[8][256]; +} list = {}; + +void insert(int e) +{ + printf("insert(e = %i);\n", e); + + assert(!list.data[0][e]); + + for (int k = 0; k < 8 && !list.data[k][e >> k]++; k++); +} + +void delete(int e) +{ + printf("delete(e = %i);\n", e); + + assert(list.data[0][e]); + + for (int k = 0; k < 8 && !--list.data[k][e >> k]; k++); +} + +void print() +{ + puts("print():"); + + void walk(int k, int i) + { + if (k >= 0) + { + int* a = &list.data[k][i >> k]; + + if (a[0]) walk(k - 1, i); + + if (a[1]) walk(k - 1, i + (1 << k)); + } + else + { + printf(" " "%i\n", i); + } + } + + walk(7, 0); +} + +int main() +{ + print(); + + insert(42); + + print(); + + insert(101); + + print(); + + delete(42); + + print(); + + insert(34); + + print(); + + insert(35); + + print(); + + insert(36); + + print(); + + delete(35); + + print(); + + return 0; +} + + + + + + + + + diff --git a/spikes/sorted-sparse-list-remove.c b/spikes/sorted-sparse-list-remove.c new file mode 100644 index 0000000..626dc5c --- /dev/null +++ b/spikes/sorted-sparse-list-remove.c @@ -0,0 +1,5 @@ + +// we need to implement this one + +// should be fairly easy +