1 | | |
2 | | |
3 | | |
4 | | |
5 | | |
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
11 | | |
12 | | |
13 | | |
14 | | |
15 | | |
16 | | |
17 | | |
18 | | |
19 | | |
20 | | |
21 | | |
22 | | |
23 | | |
24 | | |
25 | | |
26 | | |
27 | | |
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
38 | | |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | |
44 | | |
45 | | |
46 | | |
47 | | |
48 | | |
49 | | |
50 | | |
51 | | |
52 | | |
53 | | |
54 | | |
55 | | |
56 | | |
57 | | |
58 | | |
59 | | |
60 | | |
61 | | |
62 | | |
63 | | |
64 | | |
65 | | |
66 | | |
67 | | |
68 | | |
69 | | |
70 | | |
71 | | |
72 | | |
| #include "cyclic.h" | | #define CYCLIC_HASH_SIZE 4711 | | CYCLIC *cyclic_hash[CYCLIC_HASH_SIZE]; | | static void low_unlink_cyclic(CYCLIC *c) | { | 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"); | } | | void unlink_cyclic(CYCLIC *c) | { | UNSET_ONERROR(c->onerr); | low_unlink_cyclic(c); | } | | void *begin_cyclic(CYCLIC *c, | void *id, | void *th, | void *a, | void *b) | { | unsigned int h; | 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) | if(a == p->a && b==p->b && id==p->id) | return p->ret; | | 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; | SET_ONERROR(c->onerr, low_unlink_cyclic, c); | return 0; | } | | |
|