From 0899e279b32a1c8fbe583ceb3599df58f9902f88 Mon Sep 17 00:00:00 2001 From: cuz Date: Tue, 31 Oct 2000 18:25:52 +0000 Subject: [PATCH] Added a sort function git-svn-id: svn://svn.cc65.org/cc65/trunk@418 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/coll.c | 14 +++++++++++++- src/common/coll.h | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 */ -- 2.39.5