Commit ecbf5106 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Declare find_element() static.

parent 1673358d
......@@ -20,6 +20,7 @@
* @param nelem length of the sorted list
* @param x the element to find a position for
*/
static
long find_element(double x, long nelem, const double *restrict array)
{
long ii;
......@@ -29,10 +30,10 @@ long find_element(double x, long nelem, const double *restrict array)
if ( array[0] < array[nelem-1] ) // ascending order
{
/* return the length of the array if x is out of bounds */
// return the length of the array if x is out of bounds
if ( x < array[0] || x > array[nelem-1] ) return nelem;
/* search for the interval in which x fits */
// search for the interval in which x fits
// implementation: binary search algorithm
for ( ii = 1; ii < nelem; ++ii )
{
......@@ -41,7 +42,7 @@ long find_element(double x, long nelem, const double *restrict array)
// faster!
mid = (first + last) >> 1;
/* return the bigger interval border of the interval in which x fits */
// return the bigger interval border of the interval in which x fits
// if ( x >= array[mid-1] && x <= array[mid] ) break;
// faster!
if ( !(x < array[mid-1] || x > array[mid]) ) break;
......@@ -55,10 +56,10 @@ long find_element(double x, long nelem, const double *restrict array)
}
else
{
/* return the length of the array if x is out of bounds */
// return the length of the array if x is out of bounds
if ( x < array[nelem-1] || x > array[0] ) return nelem;
/* search for the interval in which x fits */
// search for the interval in which x fits
// implementation: binary search algorithm
for ( ii = 1; ii < nelem; ++ii )
{
......@@ -67,7 +68,7 @@ long find_element(double x, long nelem, const double *restrict array)
// faster!
mid = (first + last) >> 1;
/* return the bigger interval border of the interval in which x fits */
// return the bigger interval border of the interval in which x fits
// if ( x >= array[mid] && x <= array[mid-1] ) break;
// faster!
if ( !(x < array[mid] || x > array[mid-1]) ) break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment