Squid-2.2.STABLE4: Isolate Splay-tree structures Cosmetic change to isolate splay-tree structures from the rest of the code. Index: squid/include/splay.h diff -u squid/include/splay.h:1.1.1.4 squid/include/splay.h:1.1.1.4.44.1 --- squid/include/splay.h:1.1.1.4 Sat Oct 3 02:57:56 1998 +++ squid/include/splay.h Tue Jul 13 00:23:38 1999 @@ -9,8 +9,8 @@ struct _splay_node *right; } splayNode; -typedef int SPLAYCMP(const void *, splayNode *); -typedef void SPLAYWALKEE(void *, void *); +typedef int SPLAYCMP(const void *a, const void *b); +typedef void SPLAYWALKEE(void *nodedata, void *state); typedef void SPLAYFREE(void *); extern int splayLastResult; Index: squid/lib/splay.c diff -u squid/lib/splay.c:1.1.1.7 squid/lib/splay.c:1.1.1.7.2.1 --- squid/lib/splay.c:1.1.1.7 Tue Jul 13 00:09:15 1999 +++ squid/lib/splay.c Tue Jul 13 00:23:43 1999 @@ -59,11 +59,11 @@ l = r = &N; for (;;) { - splayLastResult = compare(data, top); + splayLastResult = compare(data, top->data); if (splayLastResult < 0) { if (top->left == NULL) break; - if ((splayLastResult = compare(data, top->left)) < 0) { + if ((splayLastResult = compare(data, top->left->data)) < 0) { y = top->left; /* rotate right */ top->left = y->right; y->right = top; @@ -77,7 +77,7 @@ } else if (splayLastResult > 0) { if (top->right == NULL) break; - if ((splayLastResult = compare(data, top->right)) > 0) { + if ((splayLastResult = compare(data, top->right->data)) > 0) { y = top->right; /* rotate left */ top->right = y->left; y->left = top; @@ -115,25 +115,38 @@ { if (top->left) splay_walk(top->left, walkee, state); + walkee(top->data, state); if (top->right) splay_walk(top->right, walkee, state); - walkee(top->data, state); } - +#ifdef DEBUG +void +splay_dump_entry(void *data, int depth) +{ + printf("%*s%s\n", depth, "", (char *)data); +} -#ifdef DRIVER +static void +splay_do_dump(splayNode * top, void printfunc(void *data, int depth), int depth) +{ + if(!top) return; + splay_do_dump(top->left, printfunc, depth+1); + printfunc(top->data, depth); + splay_do_dump(top->right, printfunc, depth+1); +} void -splay_print(splayNode * top, void (*printfunc) ()) +splay_dump(splayNode * top, void printfunc(void *data, int depth)) { - if (top == NULL) - return; - splay_print(top->left, printfunc); - printfunc(top->data); - splay_print(top->right, printfunc); + splay_do_dump(top, printfunc, 0); } + +#endif + +#ifdef DRIVER + typedef struct { int i; } intnode; @@ -147,10 +160,10 @@ } void -printint(void *a) +printint(void *a, void *state) { intnode *A = a; - printf("%d\n", A->i); + printf("%d\n", "", A->i); } main(int argc, char *argv[]) @@ -164,7 +177,7 @@ I->i = random(); top = splay_insert(I, top, compareint); } - splay_print(top, printint); + splay_walk(top, printint, NULL); return 0; } #endif /* DRIVER */ Index: squid/src/acl.c diff -u squid/src/acl.c:1.1.1.35 squid/src/acl.c:1.1.1.35.2.1 --- squid/src/acl.c:1.1.1.35 Tue Jul 13 00:09:21 1999 +++ squid/src/acl.c Tue Jul 13 00:23:43 1999 @@ -1886,10 +1886,10 @@ /* compare two domains */ static int -aclDomainCompare(const void *data, splayNode * n) +aclDomainCompare(const void *a, const void *b) { - const char *d1 = data; - const char *d2 = n->data; + const char *d1 = a; + const char *d2 = b; int l1; int l2; while ('.' == *d1) @@ -1926,10 +1926,10 @@ /* compare a host and a domain */ static int -aclHostDomainCompare(const void *data, splayNode * n) +aclHostDomainCompare(const void *a, const void * b) { - const char *h = data; - char *d = n->data; + const char *h = a; + const char *d = b; int l1; int l2; if (matchDomainName(d, h)) @@ -1967,12 +1967,12 @@ /* compare an address and a network spec */ static int -aclIpNetworkCompare(const void *a, splayNode * n) +aclIpNetworkCompare(const void *a, const void *b) { - struct in_addr A = *(struct in_addr *) a; - acl_ip_data *q = n->data; - struct in_addr B = q->addr1; - struct in_addr C = q->addr2; + struct in_addr A = *(const struct in_addr *) a; + const acl_ip_data *q = b; + const struct in_addr B = q->addr1; + const struct in_addr C = q->addr2; int rc = 0; A.s_addr &= q->mask.s_addr; /* apply netmask */ if (C.s_addr == 0) { /* single address check */ @@ -2309,10 +2309,10 @@ } static int -aclArpCompare(const void *data, splayNode * n) +aclArpCompare(const void *a, const void *b) { - const unsigned short *d1 = data; - const unsigned short *d2 = n->data; + const unsigned short *d1 = a; + const unsigned short *d2 = b; if (d1[0] != d2[0]) return (d1[0] > d2[0]) ? 1 : -1; if (d1[1] != d2[1])