From: cuz Date: Sat, 5 May 2001 12:34:22 +0000 (+0000) Subject: Added CollPop X-Git-Tag: V2.12.0~2849 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e8174aaa25ae4cfb71e8d87781d3dc9214dd4df7;p=cc65 Added CollPop git-svn-id: svn://svn.cc65.org/cc65/trunk@714 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/common/coll.c b/src/common/coll.c index f2cd52f7e..c552cbf0d 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -195,10 +195,24 @@ const void* CollConstLast (const Collection* C) +void* CollPop (Collection* C) +/* Remove the last segment from the stack and return it. Calls FAIL if the + * collection is empty. + */ +{ + /* We must have at least one entry */ + PRECONDITION (C->Count > 0); + + /* Return the element */ + return C->Items[--C->Count]; +} + + + int CollIndex (Collection* C, const void* Item) /* Return the index of the given item in the collection. Return -1 if the * item was not found in the collection. - */ + */ { /* Linear search */ unsigned I; diff --git a/src/common/coll.h b/src/common/coll.h index bab2ffc48..83d3e9d22 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -102,6 +102,11 @@ void* CollLast (Collection* C); const void* CollConstLast (const Collection* C); /* Return the last item in a collection */ +void* CollPop (Collection* C); +/* Remove the last segment from the stack and return it. Calls FAIL if the + * collection is empty. + */ + int CollIndex (Collection* C, const void* Item); /* Return the index of the given item in the collection. Return -1 if the * item was not found in the collection.