1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-04 13:29:35 +00:00

Added CollIndex and CollDeleteItem

git-svn-id: svn://svn.cc65.org/cc65/trunk@708 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-05-03 20:45:26 +00:00
parent 8a3bacd7f4
commit 42695dd3c3
2 changed files with 49 additions and 3 deletions

View File

@ -9,7 +9,7 @@
/* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -195,6 +195,26 @@ const void* CollConstLast (const Collection* C)
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;
for (I = 0; I < C->Count; ++I) {
if (Item == C->Items[I]) {
/* Found */
return (int)I;
}
}
/* Not found */
return -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
@ -211,10 +231,26 @@ void CollDelete (Collection* C, unsigned Index)
void CollDeleteItem (Collection* C, const void* Item)
/* Delete the item pointer from the collection. The item must be in the
* collection, otherwise FAIL will be called.
*/
{
/* Get the index of the entry */
int Index = CollIndex (C, Item);
CHECK (Index >= 0);
/* Delete the item with this index */
--C->Count;
memmove (C->Items+Index, C->Items+Index+1, (C->Count-Index) * sizeof (void*));
}
void CollDeleteAll (Collection* C)
/* Delete all items from the given collection. This will not free the items
* itself, it will only remove the pointers.
*/
*/
{
/* This one is easy... */
C->Count = 0;

View File

@ -9,7 +9,7 @@
/* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -102,12 +102,22 @@ void* CollLast (Collection* C);
const void* CollConstLast (const Collection* C);
/* Return the last item in a collection */
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.
*/
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
* will get moved to a lower position.
*/
void CollDeleteItem (Collection* C, const void* Item);
/* Delete the item pointer from the collection. The item must be in the
* collection, otherwise FAIL will be called.
*/
void CollDeleteAll (Collection* C);
/* Delete all items from the given collection. This will not free the items
* itself, it will only remove the pointers.