Update the arrayMin[F] functions so that they now return the min value and set the index. Also add arrayMax[F] versions.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4461 4a71c877-e1ca-e34f-864e-861f7616d084
master
Freddie Witherden 2008-04-01 11:26:53 +00:00
parent 4e0c1dbafd
commit 59f951b0bc
1 changed files with 58 additions and 12 deletions

View File

@ -40,7 +40,7 @@
/**
* Returns the index of the lowest value in the array.
*/
static inline int arrayMinIndex(const int *array, const size_t n, int *value)
static inline int arrayMin(const int *array, const size_t n, int *index)
{
int i, minIdx;
@ -53,17 +53,17 @@ static inline int arrayMinIndex(const int *array, const size_t n, int *value)
}
}
// If requested, store the minimum value
if (value != NULL)
// If requested, store the index of the minimum value
if (index != NULL)
{
*value = array[minIdx];
*index = minIdx;
}
// Return the array
return minIdx;
// Return the value
return array[minIdx];
}
static inline int arrayMinIndexF(const float *array, const size_t n, float *value)
static inline float arrayMinF(const float *array, const size_t n, int *index)
{
int i, minIdx;
@ -76,14 +76,60 @@ static inline int arrayMinIndexF(const float *array, const size_t n, float *valu
}
}
// If requested, store the minimum value
if (value != NULL)
// If requested, store the index of the minimum value
if (index != NULL)
{
*value = array[minIdx];
*index = minIdx;
}
// Return the array
return minIdx;
// Return the value
return array[minIdx];
}
static inline int arrayMax(const int *array, const size_t n, int *index)
{
int i, maxIdx;
// Find the index of the maximum value
for (i = maxIdx = 0; i < n; i++)
{
if (array[i] > array[maxIdx])
{
maxIdx = i;
}
}
// If requested, store the index of the maximum value
if (index != NULL)
{
*index = maxIdx;
}
// Return the value
return array[maxIdx];
}
static inline float arrayMaxF(const float *array, const size_t n, int *index)
{
int i, maxIdx;
// Find the index of the maximum value
for (i = maxIdx = 0; i < n; i++)
{
if (array[i] > array[maxIdx])
{
maxIdx = i;
}
}
// If requested, store the index of the maximum value
if (index != NULL)
{
*index = maxIdx;
}
// Return the value
return array[maxIdx];
}
/*