#include "InvertedAtomIndex.h" ConceptChainElement* conceptChainElementStoragePointers[UNIFICATION_DEPTH*CONCEPTS_MAX]; ConceptChainElement conceptChainElementStorage[UNIFICATION_DEPTH*CONCEPTS_MAX]; Stack conceptChainElementStack; ConceptChainElement *invertedAtomIndex[ATOMS_MAX]; void InvertedAtomIndex_INIT() { for(int i=0; ic = c; invertedAtomIndex[atom] = newElem; } else { //search for c: ConceptChainElement *previous = NULL; while(elem != NULL) { if(elem->c == c) { goto NEXT_ATOM; } previous = elem; elem = elem->next; } //ok, we can add it as previous->next ConceptChainElement *newElem = Stack_Pop(&conceptChainElementStack); //new item newElem->c = c; previous->next = newElem; } } NEXT_ATOM:; } } void InvertedAtomIndex_RemoveConcept(Term term, Concept *c) { for(int i=0; ic == c) //we found c in the chain, remove it { if(previous == NULL) //item was the initial chain element, let the next element be the initial now { invertedAtomIndex[atom] = elem->next; } else //item was within the chain, relink the previous to the next of elem { previous->next = elem->next; } //push elem back to the stack, it's "freed" assert(elem->c != NULL, "A null concept was in inverted atom index!"); elem->c = NULL; elem->next = NULL; Stack_Push(&conceptChainElementStack, elem); goto NEXT_ATOM; } previous = elem; elem = elem->next; } } NEXT_ATOM:; } } void InvertedAtomIndex_Print() { puts("printing inverted atom table content:"); for(int i=0; ic; assert(c != NULL, "A null concept was in inverted atom index!"); Narsese_PrintAtom(atom); fputs(" -> ", stdout); Narsese_PrintTerm(&c->term); puts(""); elem = elem->next; } } } puts("table print finish"); } ConceptChainElement* InvertedAtomIndex_GetConceptChain(Atom atom) { ConceptChainElement* ret = NULL; if(atom != 0) { ret = invertedAtomIndex[atom]; } return ret; }