15 #ifdef HAVE_UNDERSCORE
16 #define cachelookup cachelookup_
17 #define setcachelast setcachelast_
18 #define getcachelast getcachelast_
23 #define REALSIZE sizeof(double)
26 #define CPLXSIZE (2*REALSIZE)
28 #define ptrdiff(a, b) (long)((char *)a - (char *)b)
31 int cachelookup(
char *para,
char **base,
32 void (*calc)(
char *,
char *),
int *npara,
int *nval)
34 char *node, *last, **next = base;
35 const int parasize = *npara*REALSIZE;
36 const int valsize = *nval*CPLXSIZE;
42 next = (
char **)(node -
sizeof(
char *));
43 if( memcmp(para, node + valsize, parasize) == 0 )
goto done;
44 }
while( node != last );
48 node = malloc(
sizeof(
char *) + valsize + parasize + CPLXSIZE);
52 fputs(
"Out of cache memory.\n", stderr);
55 node +=
sizeof(
char *);
56 node += ptrdiff(base, node) & (CPLXSIZE - 1);
58 *(
char **)(node -
sizeof(
char *)) = NULL;
61 memcpy(node + valsize, para, parasize);
64 return ptrdiff(node, base)/CPLXSIZE;
68 void setcachelast(
char **base,
int *offset)
70 *(base + 1) = *offset ? (
char *)base + *offset*CPLXSIZE : NULL;
74 int getcachelast(
char **base)
76 return *(base + 1) ? ptrdiff(*(base + 1), base)/CPLXSIZE : 0;