diff --git a/src/common/coll.c b/src/common/coll.c index b1e946910..0b36ca463 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -158,6 +158,18 @@ void* CollAt (Collection* C, unsigned Index) +void* CollLast (Collection* C) +/* Return the last item in a collection */ +{ + /* We must have at least one entry */ + PRECONDITION (C->Count > 0); + + /* Return the element */ + return C->Items[C->Count-1]; +} + + + void CollDelete (Collection* C, unsigned Index) /* Remove the item with the given index from the collection. This will not * free the item itself, just the pointer. All items with higher indices diff --git a/src/common/coll.h b/src/common/coll.h index 9c165799b..c84e0bbff 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -81,7 +81,7 @@ Collection* NewCollection (void); void FreeCollection (Collection* C); /* Free a collection */ -unsigned CollCount (Collection* C) attribute ((const)); +unsigned CollCount (Collection* C); /* Return the number of items in the collection */ void CollInsert (Collection* C, void* Item, unsigned Index); @@ -93,6 +93,9 @@ void CollAppend (Collection* C, void* Item); void* CollAt (Collection* C, unsigned Index) attribute ((const)); /* Return the item at the given index */ +void* CollLast (Collection* C); +/* Return the last item in a collection */ + void CollDelete (Collection* C, unsigned Index); /* Remove the item with the given index from the collection. This will not * free the item itself, just the pointer. All items with higher indices