From dfeaf83327749d903e6c78dddb25cb6e172e0c87 Mon Sep 17 00:00:00 2001 From: ccremers Date: Fri, 27 Aug 2004 13:10:46 +0000 Subject: [PATCH] - Added 'termlistFind' function, which is more generic than inTermlist --- src/termlist.c | 21 +++++++++++++++++++++ src/termlist.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/termlist.c b/src/termlist.c index b674478..7caf59c 100644 --- a/src/termlist.c +++ b/src/termlist.c @@ -133,6 +133,27 @@ inTermlist (Termlist tl, const Term term) return 0; } +//! Determine whether a term is an element of a termlist: yield pointer +__inline__ Termlist termlistFind (Termlist tl, const Term term) +{ +#ifdef DEBUG + if (term == NULL) + { + error ("Trying to do inTermlist for a NULL term."); + } +#endif + while (tl != NULL) + { + if (isTermEqual (tl->term, term)) + { + return tl; + } + tl = tl->next; + } + return NULL; +} + + //! Equality of two term lists. /** * Are all elements of list 1 in list 2, and vice versa? diff --git a/src/termlist.h b/src/termlist.h index dc917a4..748ad0a 100644 --- a/src/termlist.h +++ b/src/termlist.h @@ -29,6 +29,7 @@ void termlistDelete (Termlist tl); void termlistDestroy (Termlist tl); void termlistPrint (Termlist tl); __inline__ int inTermlist (Termlist tl, const Term term); +__inline__ Termlist termlistFind (Termlist tl, const Term term); int isTermlistEqual (Termlist tl1, Termlist tl2); Termlist termlistAdd (Termlist tl, Term term); Termlist termlistAppend (const Termlist tl, const Term term);