From 2452a346713e4bd85f77a7357b0210a298521ba1 Mon Sep 17 00:00:00 2001 From: ccremers Date: Sat, 8 Oct 2005 19:56:04 +0000 Subject: [PATCH] - 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. --- src/termlist.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++- src/termlist.h | 1 + 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/termlist.c b/src/termlist.c index 5373259..110ba78 100644 --- a/src/termlist.c +++ b/src/termlist.c @@ -5,10 +5,27 @@ #include "debug.h" #include "memory.h" +/** + * Shared stuff + */ + +//! Termlist error thing (for global use) +Termlist TERMLISTERROR; + +/** + * Forward declarations + */ + +Termlist makeTermlist (); + //! Open termlists code. void termlistsInit (void) { + TERMLISTERROR = makeTermlist (); + TERMLISTERROR->term = NULL; + TERMLISTERROR->prev = NULL; + TERMLISTERROR->next = NULL; return; } @@ -16,6 +33,7 @@ termlistsInit (void) void termlistsDone (void) { + termlistDelete (TERMLISTERROR); return; } @@ -81,6 +99,19 @@ termlistDelete (Termlist tl) { if (tl == NULL) 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); memFree (tl, sizeof (struct termlist)); } @@ -614,7 +645,7 @@ inverseKey (Termlist inverses, Term key) *\sa termlistLocal() */ Term -termLocal (Term t, Termlist fromlist, Termlist tolist) +termLocal (const Term t, Termlist fromlist, Termlist tolist) { if (t == 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; +} diff --git a/src/termlist.h b/src/termlist.h index f7783be..84caf83 100644 --- a/src/termlist.h +++ b/src/termlist.h @@ -57,5 +57,6 @@ int termlistOrder (Termlist tl1, Termlist tl2); int termlist_iterate (Termlist tl, int (*func) ()); Term termlist_to_tuple (Termlist tl); Termlist tuple_to_termlist (Term t); +Termlist termlistMinusTermlist (const Termlist tlbig, const Termlist tlsmall); #endif