Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: "Wessels, Hans" <H.Wessels@energie-delfland.nl>
To: "'axp-list@redhat.com'" <axp-list@redhat.com>
Subject: RE: Binary search speed in Alpha
Date: Fri, 27 Nov 1998 14:58:54 +0100	[thread overview]
Message-ID: <c=US%a=_%p=delfland%l=MSMAIL-981127135854Z-6200@msmail.energie-delfland.nl> (raw)

Hi  Jaap,

>double getval_short(TBL *tab, double xval)
>{
>	unsigned long index,mid,lo,up,n;
>	int ascnd;
>	double top,bott,rico;
>
>	/* first check high and low points */	
>	if (xval <= tab->x[0])
>		return tab->y[0];
>	else if (xval >= tab->x[(tab->points) - 1])
>		return tab->y[(tab->points) - 1];
>
>	/* Find position in array: x[index] < xval < x[index +1]*/
>	n = tab->points;
>	lo = -1; up = n;
>
>	ascnd = (tab->x[n - 1] >= tab->x[0]);
>	while (up - lo > 1){
>		mid = (up + lo) >> 1;
>		if (xval >= tab->x[mid] == ascnd)
>			lo = mid;
>		else
>			up = mid;
>	}
>	if ( xval == tab->x[0])  index = 0;
>	else if (xval == tab->x[n-1]) index =  n - 2;
>	else index = lo;
>
>	/* linear interpolation */
>	top = (tab->y[index + 1] - tab->y[index]);
>	bott = (tab->x[index + 1] - tab->x[index]);
>	rico =  top/bott;
>	return (rico * (xval - tab->x[index])) + tab->y[index];
>}
>

Tried to change your data structures?

From what y read TAB is something like:
struct TAB_struct
{
  int points;
  double x[];
  double y[];
} TAB;

try something like
struct coord_struct
{
  double x;
  double y;
}

struct TAB_struct
{
  struct coord_struct c[];
  int points;
}

If your coordinates are allocated dynamicly get the pointer local in
your function:
{
  struct coord_struct* = tab->c;
}

so no double pointer dereferencing is needed (don't know how good gcc or
egcs is with tricks like that).

Bye, Hans

----------------------------------------------------------------------
   /|   /\/\/\   |\      ir. Hans Wessels
  / |  / /\/\ \  | \     H.Wessels@Energie-Delfland.nl
 /  | / / /\ \ \ |  \    tel.: 015 251 4397
/   |/ / /  \ \ \|   \   
\   |\ \ \  / / /|   /   prive:
 \  | \ \ \/ / / |  /    mr_ni@mbh.org
  \ |  \ \/\/ /  | /     Fidelus Bittus et Fuckus Clockcyclus!
   \|   \/\/\/   |/      


             reply	other threads:[~1998-11-27 14:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-27 13:58 Wessels, Hans [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-11-27 10:07 Binary search speed in Alpha Jaap Schellekens
1998-11-27  8:58 ` Matti Aarnio
1998-11-27 13:27   ` Jaap Schellekens
1998-11-28 19:12     ` Bibek Sahu
1998-11-28 19:36       ` Jaap Schellekens
1998-11-28 20:46         ` Dave Gilbert
1998-11-29 16:54           ` Jaap Schellekens
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox