-
Notifications
You must be signed in to change notification settings - Fork 0
/
DNFCMD.c
103 lines (76 loc) · 2.16 KB
/
DNFCMD.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//Defining functions to have DNFs work with each other
#include "ADNF.h"
#include <stdlib.h>
void CPYTO(ADNFClause dst, ADNFClause src) //Both are considered HEADS
{
src=src->next;
while (src)
{
//dst to catch up with src
dst-> next= malloc(sizeof(AAndClause));
dst-> next-> prev= dst;
dst= dst->next;
//The actual copying
dst->set= src->set;
//src move on
src= src->next;
}
}
ADNFClause CPY(ADNFClause src)
{
ADNFClause dst;
dst= malloc(sizeof(AAndClause));
dst->prev=0;
CPYTO(dst, src);
return dst;
}
//ADNFClause AND( ASet dst, ADNFClause src) //Returns a linked list of length>=1 "WITHOUT A HEAD"
//{
// ADNFClause
//}
void AND( ADNFClause dst, ADNFClause src)
{
ADNFClause newChainEnd; //the CURRENT tail of the new chain of and clauses
ADNFClause oldChainI; //old chain iterator
// ADNFClause oldCur;
ADNFClause srcI; //source iterator
ADNFClause t; //temp!
oldChainI=dst->next; //to read the original and clauses from the original linked list
newChainEnd=dst; //the head
newChainEnd->next=0;//empty list for now
while (oldChainI)
{
for (srcI= src->next; srcI; srcI= srcI->next) //traverse the other operand to and all the and clauses!
{
t=AddClause( newChainEnd, srcI->set | oldChainI->set); //if it's not added, t=0!
//Orring two sets means their union, therefore ANDing the and clauses
newChainEnd= (t)? (Last(t)): (newChainEnd); //if the new clause is not added, it has not deleted anything either
}
t= oldChainI->next;
free(oldChainI);
oldChainI= t;
}
}
void OR ( ADNFClause dst, ADNFClause src)
{
for (src=src->next; src; src=src->next)
AddClause(dst, src->set);
}
void NOT( ADNFClause dst)
{
ADNFClause oldChainHead;
ADNFClause newORClause; //each previously AND clause becomes an OR clause
int i;
oldChainHead->next= dst->next;
oldChainHead->prev= 0;
dst->next=0;
InitAndClauseLinkedList(&newORClause);
for (oldChainHead= oldChainHead->next; oldChainHead; oldChainHead= oldChainHead->next)
{
for (i=0; i<ASET_SIZE; i++)
if (SET_MEMBER(oldChainHead->set, i))
AddClause(newORClause, SET_ADDE(0, SET_INDEX_NEGATE(i)));
AND(dst, newORClause);
ClearDNFClause(newORClause);
}
}