24ddc7 | 1998-03-28 | Henrik Grubbström (Grubba) | | #include "global.h"
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | #include "cyclic.h"
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | RCSID("$Id: cyclic.c,v 1.4 2000/05/07 00:39:17 hubbe Exp $");
|
24ddc7 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | #define CYCLIC_HASH_SIZE 4711
CYCLIC *cyclic_hash[CYCLIC_HASH_SIZE];
|
545ca8 | 1997-10-07 | Fredrik Hübinette (Hubbe) | | static void low_unlink_cyclic(CYCLIC *c)
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | {
unsigned int h;
CYCLIC **p;
h=(int)c->id;
h*=33;
h|=(int)c->a;
h*=33;
h|=(int)c->b;
h*=33;
h|=(int)c->th;
h*=33;
h%=CYCLIC_HASH_SIZE;
for(p=cyclic_hash+h;*p;p=&(p[0]->next))
{
if(c == *p)
{
*p=c->next;
return;
}
}
fatal("Unlink cyclic on lost cyclic struct.\n");
}
|
545ca8 | 1997-10-07 | Fredrik Hübinette (Hubbe) | | void unlink_cyclic(CYCLIC *c)
{
UNSET_ONERROR(c->onerr);
low_unlink_cyclic(c);
}
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | void *begin_cyclic(CYCLIC *c,
void *id,
void *th,
void *a,
void *b)
{
unsigned int h;
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | void *ret=0;
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | CYCLIC *p;
h=(int)id;
h*=33;
h|=(int)a;
h*=33;
h|=(int)b;
h*=33;
h|=(int)th;
h*=33;
h%=CYCLIC_HASH_SIZE;
for(p=cyclic_hash[h];p;p=p->next)
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | {
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | if(a == p->a && b==p->b && id==p->id)
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | {
ret=p->ret;
break;
}
}
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | |
c->ret=(void *)1;
c->a=a;
c->b=b;
c->id=id;
c->th=th;
c->next=cyclic_hash[h];
cyclic_hash[h]=c;
|
545ca8 | 1997-10-07 | Fredrik Hübinette (Hubbe) | | SET_ONERROR(c->onerr, low_unlink_cyclic, c);
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | return ret;
|
fc3345 | 1997-10-02 | Fredrik Hübinette (Hubbe) | | }
|