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 */