CSFLOC rewrite

Signed-off-by: gothictomato <gothictomato@pm.me>
This commit is contained in:
gothictomato
2022-09-04 10:52:28 -04:00
parent e2b633c802
commit 53a580d0ec
9 changed files with 761 additions and 228 deletions

27
ncnf.c
View File

@@ -60,6 +60,8 @@ cnf* readDIMACS(char* path) {
c->clausedat = calloc(*clausecnt, sizeof(u32) * 3);
CHECK(c->clausedat, "Failed to allocate clause data\n")
c->index = calloc(*varcnt, sizeof(u32));
CHECK(c->index, "Failed to allocate clause index\n")
c->variables = calloc(cap, sizeof(u32));
CHECK(c->variables, "Failed to allocate literal variables\n")
c->parities = calloc(cap, sizeof(u8));
@@ -208,4 +210,29 @@ void sortlastnum(cnf* c) {
}
free(d);
// TODO: Rewrite, the following is copied from Gábor Kusper's implementation
u32 lastNum = 0;
for (u32 i = c->cnts[1] - 1; i < c->cnts[1]; --i) {
if (c->clausedat[3 * i + 2] > lastNum) {
while (lastNum < c->clausedat[3 * i + 2]) {
c->index[lastNum] = i + 1;
lastNum++;
}
}
}
u32 corrInd = 0;
while (c->index[corrInd] == c->cnts[1]) {
corrInd++;
}
if (corrInd != 0) {
u32 goodVal = c->index[corrInd];
do {
corrInd--;
c->index[corrInd] = goodVal;
} while (corrInd != 0);
}
}