/*--------------------------------------------------------------------------- These are the routines to manage the structure dictionary. The structure dictionary is a linked list of all the term loxes used by all the databases. No logical connectives (OR NOT...) or quantifiers are stored in the dictionary, only literals. The entries are sorted by predicate token id. They are linked by the brother (b) pointer of the predicate. */ #include #include #include #include "glob.h" static lox *FirstOne = NULL; /*--------------------------------------------------------------------------- Insert new lox tree to the struc list */ int AddStrucs(lox *t) { lox *a,*b,*p; if (t==NULL) return 0; switch (t->type) { case AND: case OR: a = t->a; b = t->b; t->a = t->b = NULL; FreeLox(t); AddStrucs(a); AddStrucs(b); break; case ALL: case SOME: b = t->b; t->b = NULL; FreeLox(t); AddStrucs(b); break; case NOT: a = t->a; t->a = NULL; FreeLox(t); AddStrucs(a); break; default: if (t->type != TERM) eprintf("Invalid struc added to dictionary, type=%d",t->type,0,0); p = FirstOne; if (p==NULL || p->id > t->id) { FirstOne = t; t->b = p; return 0; } while (1) { if (t==p) break; if (p->b == NULL || p->b->id > t->id) { t->b = p->b; p->b = t; break; } p = p->b; } } return 0; }