From: cuz Date: Tue, 31 Oct 2000 18:25:52 +0000 (+0000) Subject: Added a sort function X-Git-Tag: V2.12.0~3108 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0899e279b32a1c8fbe583ceb3599df58f9902f88;p=cc65 Added a sort function git-svn-id: svn://svn.cc65.org/cc65/trunk@418 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/common/coll.c b/src/common/coll.c index 232438d8a..8ce56a8c7 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -33,6 +33,7 @@ +#include #include /* common */ @@ -164,7 +165,7 @@ const void* CollConstAt (const Collection* C, unsigned Index) /* Check the index */ PRECONDITION (Index < C->Count); - /* Return the element */ + /* Return the element */ return C->Items[Index]; } @@ -224,4 +225,15 @@ void CollReplace (Collection* C, void* Item, unsigned Index) +void CollSort (Collection* C, int (*Compare) (const void*, const void*)) +/* Sort the collection using the given compare function. + * BEWARE: The function uses qsort internally, so the Compare function does + * actually get pointers to the object pointers, not just object pointers! + */ +{ + /* Use qsort */ + qsort (C->Items, C->Count, sizeof (void*), Compare); +} + + diff --git a/src/common/coll.h b/src/common/coll.h index ca39b1441..144442f65 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -113,6 +113,12 @@ void CollReplace (Collection* C, void* Item, unsigned Index); * just the pointer will et replaced. */ +void CollSort (Collection* C, int (*Compare) (const void*, const void*)); +/* Sort the collection using the given compare function. + * BEWARE: The function uses qsort internally, so the Compare function does + * actually get pointers to the object pointers, not just object pointers! + */ + /* End of exprlist.h */