- More additions to the documentation.

This commit is contained in:
ccremers 2004-05-15 14:22:44 +00:00
parent 4e5d28e45c
commit a21e1b73e4
3 changed files with 124 additions and 65 deletions

View File

@ -1,3 +1,9 @@
/**
*@file debug.c
*\brief Debugging code.
*
* It is hoped that this code will become redundant over time.
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "debug.h" #include "debug.h"
@ -5,18 +11,33 @@
static int debuglevel; static int debuglevel;
//! Set the debuglevel from the main code.
void void
debugSet (int level) debugSet (int level)
{ {
debuglevel = level; debuglevel = level;
} }
//! Test whether some debuglevel is meant to be printed.
/**
*@param level The debuglevel
*@return True iff level is smaller than, or equal to, the last set debuglevel.
*\sa debugSet()
*/
int int
debugCond (int level) debugCond (int level)
{ {
return (level <= debuglevel); return (level <= debuglevel);
} }
//! Print some debug string for some level, if desired.
/**
*@param level The debuglevel
*@param string The string to be displayed for this level.
*@return If the debuglevel is higher than the level, the string is ignored.
* Otherwise it will be printed.
*\sa debugCond()
*/
void void
debug (int level, char *string) debug (int level, char *string)
{ {

View File

@ -1,3 +1,9 @@
/**
*@file knowledge.c
*\brief Procedures concerning knowledge structures.
*
* The main issue of this code is to maintain the minimal property of the knowledge set.
*/
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "termlists.h" #include "termlists.h"
@ -20,23 +26,34 @@
* they now have some overhead. * they now have some overhead.
*/ */
//! Open knowledge code.
void void
knowledgeInit (void) knowledgeInit (void)
{ {
return; return;
} }
//! Close knowledge code.
void void
knowledgeDone (void) knowledgeDone (void)
{ {
} }
//! Allocate a fresh memory block the size of a knowledge struct.
/**
* Memory will not be initialized.
*@return Pointer to a fresh memory block.
*/
Knowledge Knowledge
makeKnowledge () makeKnowledge ()
{ {
return (Knowledge) memAlloc (sizeof (struct knowledge)); return (Knowledge) memAlloc (sizeof (struct knowledge));
} }
//! Create a new empty knowledge structure.
/**
*@return Pointer to an empty knowledge structure.
*/
Knowledge Knowledge
emptyKnowledge () emptyKnowledge ()
{ {
@ -50,6 +67,15 @@ emptyKnowledge ()
return know; return know;
} }
//! Duplicate a knowledge structure.
/**
* Makes copies using termlistShallow() of knowledge::basic, knowledge::encrypt and
* knowledge::vars.
* For the inverses, only the pointer is copied.
*@param know The knowledge structure to be copied.
*@return A pointer to a new memory struct.
*\sa termlistShallow(), knowledgeDelete()
*/
Knowledge Knowledge
knowledgeDuplicate (Knowledge know) knowledgeDuplicate (Knowledge know)
{ {
@ -68,6 +94,11 @@ knowledgeDuplicate (Knowledge know)
return newknow; return newknow;
} }
//! Delete a knowledge set.
/**
* Typically used to destroy something made with knowledgeDuplicate().
*\sa knowledgeDuplicate()
*/
void void
knowledgeDelete (Knowledge know) knowledgeDelete (Knowledge know)
{ {
@ -80,6 +111,12 @@ knowledgeDelete (Knowledge know)
} }
} }
//! Destroy a knowledge set.
/**
* Unlike knowledgeDelete(), uses termlistDestroy() to remove knowledge::basic,
* knowledge::encrypt and knowledge::vars substructures.
*\sa knowledgeDelete()
*/
void void
knowledgeDestroy (Knowledge know) knowledgeDestroy (Knowledge know)
{ {
@ -93,13 +130,12 @@ knowledgeDestroy (Knowledge know)
} }
} }
/* //! Add a term to a knowledge set.
* knowledgeAddTerm /**
* *@param know The knowledge set.
* returns a boolean: *@param term The term to be added.
* true iff the term was actually new, and added. *@return True iff the term was actually new, and added.
*/ */
int int
knowledgeAddTerm (Knowledge know, Term term) knowledgeAddTerm (Knowledge know, Term term)
{ {
@ -156,11 +192,12 @@ knowledgeAddTerm (Knowledge know, Term term)
} }
/* //! Try to simplify knowledge based on a term.
Note: the input is a key k, i.e. it can decrypt /**
anything that was encrypted with k^{-1}. *@param know A knowledge set.
*@param term A key, i.e. it can decrypt
anything that was encrypted with term^{-1}.
*/ */
void void
knowledgeSimplify (Knowledge know, Term key) knowledgeSimplify (Knowledge know, Term key)
{ {
@ -184,12 +221,11 @@ knowledgeSimplify (Knowledge know, Term key)
termlistDelete (tldecrypts); termlistDelete (tldecrypts);
} }
//! Add a termlist to the knowledge.
/* /*
* Add a whole termlist. *@return True iff there was at least one new item.
* *\sa knowledgeAddTerm()
* Returns true iff there was at least one new item.
*/ */
int int
knowledgeAddTermlist (Knowledge know, Termlist tl) knowledgeAddTermlist (Knowledge know, Termlist tl)
{ {
@ -203,12 +239,7 @@ knowledgeAddTermlist (Knowledge know, Termlist tl)
return flag; return flag;
} }
/* //! Add an inverse pair to the knowledge
add an inverse pair to the knowledge
*/
void void
knowledgeAddInverse (Knowledge know, Term t1, Term t2) knowledgeAddInverse (Knowledge know, Term t1, Term t2)
{ {
@ -217,24 +248,22 @@ knowledgeAddInverse (Knowledge know, Term t1, Term t2)
return; return;
} }
/* //! Set an inverse pair list for the knowledge.
same, but for list. List pointer is simply copied, so don't delete it later! /**
* List pointer is simply copied, so don't delete it later!
*/ */
void void
knowledgeSetInverses (Knowledge know, Termlist tl) knowledgeSetInverses (Knowledge know, Termlist tl)
{ {
know->inverses = tl; know->inverses = tl;
} }
/* //! Is a term a part of the knowledge?
/**
inKnowledge *@param know The knowledge set.
*@param term The term to be inferred.
Is a term a part of the knowledge? *@return True iff the term can be inferred from the knowledge set.
*/ */
int int
inKnowledge (const Knowledge know, Term term) inKnowledge (const Knowledge know, Term term)
{ {
@ -266,6 +295,11 @@ inKnowledge (const Knowledge know, Term term)
return 0; /* unrecognized term type, weird */ return 0; /* unrecognized term type, weird */
} }
//! Compare two knowledge sets.
/**
* This does not check currently for equivalence of inverse sets, which it should.
*@return True iff both knowledge sets are equal.
*/
int int
isKnowledgeEqual (Knowledge know1, Knowledge know2) isKnowledgeEqual (Knowledge know1, Knowledge know2)
{ {
@ -281,7 +315,7 @@ isKnowledgeEqual (Knowledge know1, Knowledge know2)
return isTermlistEqual (know1->basic, know2->basic); return isTermlistEqual (know1->basic, know2->basic);
} }
//! Print a knowledge set.
void void
knowledgePrint (Knowledge know) knowledgePrint (Knowledge know)
{ {
@ -304,10 +338,7 @@ knowledgePrint (Knowledge know)
printf ("\n"); printf ("\n");
} }
/* //! Print the inverses list of a knowledge set.
print inverses
*/
void void
knowledgeInversesPrint (Knowledge know) knowledgeInversesPrint (Knowledge know)
{ {
@ -344,11 +375,11 @@ knowledgeInversesPrint (Knowledge know)
} }
} }
/* //! Yield the set of representatives for the knowledge.
give the set of representatives for the knowledge. /**
Note: this is a shallow copy, and needs to be termlistDelete'd. * Note: this is a shallow copy, and needs to be termlistDelete'd.
*\sa termlistDelete()
*/ */
Termlist Termlist
knowledgeSet (Knowledge know) knowledgeSet (Knowledge know)
{ {
@ -359,11 +390,10 @@ knowledgeSet (Knowledge know)
return termlistConcat (tl1, tl2); return termlistConcat (tl1, tl2);
} }
/* //! Get the inverses pointer of the knowledge.
get the inverses pointer of the knowledge. /**
Essentially the inverse function of knowledgeSetInverses * Essentially the inverse function of knowledgeSetInverses()
*/ */
Termlist Termlist
knowledgeGetInverses (Knowledge know) knowledgeGetInverses (Knowledge know)
{ {
@ -373,10 +403,13 @@ knowledgeGetInverses (Knowledge know)
return know->inverses; return know->inverses;
} }
/* //! check whether any substitutions where made in a knowledge set.
* check whether any substitutions where made at all. /**
* Typically, when a substitution is made, a knowledge set has to be reconstructed.
* This procedure detects this by checking knowledge::vars.
*@return True iff an open variable was later closed by a substitution.
*\sa knowledgeReconstruction()
*/ */
int int
knowledgeSubstNeeded (const Knowledge know) knowledgeSubstNeeded (const Knowledge know)
{ {
@ -394,13 +427,13 @@ knowledgeSubstNeeded (const Knowledge know)
return 0; return 0;
} }
/* //! Reconstruct a knowledge set.
* knowledgeReconstruction /**
*
* This is useful after e.g. substitutions. * This is useful after e.g. substitutions.
* Just rebuilds the knowledge in a new (shallow) copy. * Just rebuilds the knowledge in a new (shallow) copy.
*@return The pointer to the new knowledge.
*\sa knowledgeSubstNeeded()
*/ */
Knowledge Knowledge
knowledgeReconstruction (const Knowledge know) knowledgeReconstruction (const Knowledge know)
{ {
@ -412,13 +445,12 @@ knowledgeReconstruction (const Knowledge know)
return newknow; return newknow;
} }
/* //! Propagate any substitutions just made.
* propagate any substitutions just made. /**
*
* This usually involves reconstruction of the complete knowledge, which is * This usually involves reconstruction of the complete knowledge, which is
* 'cheaper' than a thorough analysis, so we always make a copy. * 'cheaper' than a thorough analysis, so we always make a copy.
*\sa knowledgeReconstruction()
*/ */
Knowledge Knowledge
knowledgeSubstDo (const Knowledge know) knowledgeSubstDo (const Knowledge know)
{ {
@ -426,10 +458,10 @@ knowledgeSubstDo (const Knowledge know)
return knowledgeReconstruction (know); return knowledgeReconstruction (know);
} }
/* //! Undo substitutions that were not propagated yet.
* Undo the substitutions just made. Note that this does not work anymore after knowledgeSubstDo! /**
* Undo the substitutions just made. Note that this does not work anymore after knowledgeSubstDo()
*/ */
void void
knowledgeSubstUndo (const Knowledge know) knowledgeSubstUndo (const Knowledge know)
{ {
@ -443,11 +475,13 @@ knowledgeSubstUndo (const Knowledge know)
} }
} }
/* //! Yield the minimal set of terms that are in some knowledge, but not in some other set.
* knowledgeNew(old,new) /**
* * Yield a termlist (or NULL) that represents the reduced items that are
* yield a termlist (or NULL) that represents the reduced items that are
* in the new set, but not in the old one. * in the new set, but not in the old one.
*@param oldk The old knowledge.
*@param newk The new knowledge, possibly with new terms.
*@return A termlist of miminal terms in newk, but not in oldk.
*/ */
Termlist Termlist

View File

@ -24,6 +24,10 @@ struct knowledge
* and we need to reconstruct the knowledge set. * and we need to reconstruct the knowledge set.
*/ */
Termlist vars; // special: denotes unsubstituted variables Termlist vars; // special: denotes unsubstituted variables
//! Next pointer.
/**
* Presumably obsolete.
*/
struct knowledge *next; // use for alternative memory management. struct knowledge *next; // use for alternative memory management.
}; };
}; };