From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 16838 invoked from network); 27 Nov 1998 14:01:14 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 27 Nov 1998 14:01:14 -0000 Received: from alphatje.NL.net (alphatje.NL.net [193.78.240.11]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id JAA04571 for ; Fri, 27 Nov 1998 09:00:29 -0500 Received: from [195.193.204.42] ([195.193.204.42]:38149 "HELO msmail.energie-delfland.nl" ident: "TIMEDOUT") by alphatje.NL.net with SMTP id <233752-31710>; Fri, 27 Nov 1998 14:59:30 +0100 Received: by msmail.energie-delfland.nl with SMTP (Microsoft Exchange Server Internet Mail Connector Version 4.0.995.52) id <01BE1A16.749001F0@msmail.energie-delfland.nl>; Fri, 27 Nov 1998 14:58:56 +0100 Message-ID: From: "Wessels, Hans" To: "'axp-list@redhat.com'" Subject: RE: Binary search speed in Alpha Date: Fri, 27 Nov 1998 14:58:54 +0100 X-Mailer: Microsoft Exchange Server Internet Mail Connector Version 4.0.995.52 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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! \| \/\/\/ |/