- Added 'termlistMinusTermlist' function.

- Added TERMLISTERROR constant, and corresponding tests.
  Note that this will not work in many contexts, because only NULL is
  usually considered to be a special value. It is purely intended for
  the new type evaluation functions in type.c.
This commit is contained in:
ccremers 2005-10-08 19:56:04 +00:00
parent fe730716ca
commit 2452a34671
2 changed files with 64 additions and 1 deletions

View File

@ -5,10 +5,27 @@
#include "debug.h" #include "debug.h"
#include "memory.h" #include "memory.h"
/**
* Shared stuff
*/
//! Termlist error thing (for global use)
Termlist TERMLISTERROR;
/**
* Forward declarations
*/
Termlist makeTermlist ();
//! Open termlists code. //! Open termlists code.
void void
termlistsInit (void) termlistsInit (void)
{ {
TERMLISTERROR = makeTermlist ();
TERMLISTERROR->term = NULL;
TERMLISTERROR->prev = NULL;
TERMLISTERROR->next = NULL;
return; return;
} }
@ -16,6 +33,7 @@ termlistsInit (void)
void void
termlistsDone (void) termlistsDone (void)
{ {
termlistDelete (TERMLISTERROR);
return; return;
} }
@ -81,6 +99,19 @@ termlistDelete (Termlist tl)
{ {
if (tl == NULL) if (tl == NULL)
return; return;
#ifdef DEBUG
if (tl == TERMLISTERROR)
{
static int count = 0;
count++;
if (count > 1)
{
// TERMLISTERROR should only be destroyed once (by the done function)
error ("Trying to delete TERMLISTERROR a second time, whazzup?");
}
}
#endif
termlistDelete (tl->next); termlistDelete (tl->next);
memFree (tl, sizeof (struct termlist)); memFree (tl, sizeof (struct termlist));
} }
@ -614,7 +645,7 @@ inverseKey (Termlist inverses, Term key)
*\sa termlistLocal() *\sa termlistLocal()
*/ */
Term Term
termLocal (Term t, Termlist fromlist, Termlist tolist) termLocal (const Term t, Termlist fromlist, Termlist tolist)
{ {
if (t == NULL) if (t == NULL)
return NULL; return NULL;
@ -881,3 +912,34 @@ tuple_to_termlist (Term t)
} }
} }
} }
//! Remove all items from tlbig that occur in tlsmall, and return the pointer to the new tlbig.
Termlist
termlistMinusTermlist (const Termlist tlbig, const Termlist tlsmall)
{
Termlist tl;
Termlist tlnewstart;
tl = tlbig;
tlnewstart = tlbig;
while (tl != NULL)
{
if (inTermlist (tlsmall, tl->term))
{
Termlist tlnext;
// Remember next node.
tlnext = tl->next;
// This node should be removed.
tlnewstart = termlistDelTerm (tl);
// Skip to next.
tl = tlnext;
}
else
{
// This item will remain in the list.
tl = tl->next;
}
}
return tlnewstart;
}

View File

@ -57,5 +57,6 @@ int termlistOrder (Termlist tl1, Termlist tl2);
int termlist_iterate (Termlist tl, int (*func) ()); int termlist_iterate (Termlist tl, int (*func) ());
Term termlist_to_tuple (Termlist tl); Term termlist_to_tuple (Termlist tl);
Termlist tuple_to_termlist (Term t); Termlist tuple_to_termlist (Term t);
Termlist termlistMinusTermlist (const Termlist tlbig, const Termlist tlsmall);
#endif #endif