instead of sparse-lists, why not boolean arrays?

This commit is contained in:
Zander Thannhauser 2025-06-15 19:45:05 -05:00
parent 82a102c421
commit 27bef1109d
4 changed files with 104 additions and 26 deletions

28
main.c
View file

@ -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
{

View file

97
spikes/boolean-array.c Normal file
View file

@ -0,0 +1,97 @@
#include <stdbool.h>
#include <assert.h>
#include <stdio.h>
#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;
}

View file

@ -0,0 +1,5 @@
// we need to implement this one
// should be fairly easy