- Split GSIArrayInsertionPosition function and create GSIArraySearch function.

- The definition of GSIArrayItem (#define) allows the use of GSIArray with a 
customized C type (without the syntax needed to access a GSUNION)

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24967 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Xavier Glattard 2007-04-05 08:42:40 +00:00
parent 813c52db5c
commit 6a68e09d48

View file

@ -105,6 +105,8 @@ extern "C" {
#define GSI_ARRAY_TYPES GSUNION_ALL
#endif
#ifndef GSIArrayItem
/*
* Set up the name of the union to store array elements.
*/
@ -137,6 +139,8 @@ extern "C" {
*/
#include <GNUstepBase/GSUnion.h>
#endif /* #ifndef GSIArrayItem */
struct _GSIArray {
GSIArrayItem *ptr;
unsigned count;
@ -295,7 +299,7 @@ GSIArrayAddItemNoRetain(GSIArray array, GSIArrayItem item)
* if it is greater, and NSOrderedSame if it is equal.
*/
static INLINE unsigned
GSIArrayInsertionPosition(GSIArray array, GSIArrayItem item,
GSIArraySearch(GSIArray array, GSIArrayItem item,
NSComparisonResult (*sorter)(GSIArrayItem, GSIArrayItem))
{
unsigned int upper = array->count;
@ -304,6 +308,7 @@ GSIArrayInsertionPosition(GSIArray array, GSIArrayItem item,
/*
* Binary search for an item equal to the one to be inserted.
* Only for sorted array !
*/
for (index = upper/2; upper != lower; index = (upper+lower)/2)
{
@ -323,6 +328,16 @@ GSIArrayInsertionPosition(GSIArray array, GSIArrayItem item,
break;
}
}
return index;
}
static INLINE unsigned
GSIArrayInsertionPosition(GSIArray array, GSIArrayItem item,
NSComparisonResult (*sorter)(GSIArrayItem, GSIArrayItem))
{
unsigned int index;
index = GSIArraySearch(array,item,sorter);
/*
* Now skip past any equal items so the insertion point is AFTER any
* items that are equal to the new one.