/*
- * DEBUG: section 53 Radix Tree data structure implementation
- * AUTHOR: NetBSD Derived
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
/*
* @(#)radix.c 8.4 (Berkeley) 11/2/94
*/
+/*
+ * DEBUG: section 53 Radix Tree data structure implementation
+ */
+
#include "squid.h"
#include "radix.h"
#include "util.h"
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#define rn_l rn_u.rn_node.rn_L
#define rn_r rn_u.rn_node.rn_R
#define rm_mask rm_rmu.rmu_mask
-#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
+#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
/* Helper macros */
#define squid_Bcmp(a, b, l) (l == 0 ? 0 : memcmp((caddr_t)(a), (caddr_t)(b), (u_long)l))
#define squid_R_Malloc(p, t, n) (p = (t) xmalloc((unsigned int)(n)))
#define squid_Free(p) xfree((char *)p)
#define squid_MKGet(m) {\
- if (squid_rn_mkfreelist) {\
- m = squid_rn_mkfreelist; \
- squid_rn_mkfreelist = (m)->rm_mklist; \
- } else \
- squid_R_Malloc(m, struct squid_radix_mask *, sizeof (*(m)));\
- }
+ if (squid_rn_mkfreelist) {\
+ m = squid_rn_mkfreelist; \
+ squid_rn_mkfreelist = (m)->rm_mklist; \
+ } else \
+ squid_R_Malloc(m, struct squid_radix_mask *, sizeof (*(m)));\
+ }
#define squid_MKFree(m) { (m)->rm_mklist = squid_rn_mkfreelist; squid_rn_mkfreelist = (m);}
t = t->rn_dupedkey;
return t;
on1:
- test = (*cp ^ *cp2) & 0xff; /* find first bit that differs */
+ test = (*cp ^ *cp2) & 0xff; /* find first bit that differs */
for (b = 7; (test >>= 1) > 0;)
b--;
matched_off = cp - v;
x = x->rn_r;
else
x = x->rn_l;
- } while (b > (unsigned) x->rn_b); /* x->rn_b < b && x->rn_b >= 0 */
+ } while (b > (unsigned) x->rn_b); /* x->rn_b < b && x->rn_b >= 0 */
#ifdef RN_DEBUG
if (rn_debug)
fprintf(stderr, "squid_rn_insert: Going In:\n");
else
p->rn_r = t;
x->rn_p = t;
- t->rn_p = p; /* frees x, p as temp vars below */
+ t->rn_p = p; /* frees x, p as temp vars below */
if ((cp[t->rn_off] & t->rn_bmask) == 0) {
t->rn_r = x;
} else {
return (x);
}
-static int /* XXX: arbitrary ordering for non-contiguous masks */
+static int /* XXX: arbitrary ordering for non-contiguous masks */
rn_lexobetter(void *m_arg, void *n_arg)
{
register u_char *mp = m_arg, *np = n_arg, *lim;
if (*mp > *np)
- return 1; /* not really, but need to check longer one first */
+ return 1; /* not really, but need to check longer one first */
if (*mp == *np)
for (lim = mp + *mp; mp < lim;)
if (*mp++ > *np++)
return (0);
if (netmask == 0 ||
(tt->rn_mask &&
- ((b_leaf < tt->rn_b) || /* index(netmask) > node */
+ ((b_leaf < tt->rn_b) || /* index(netmask) > node */
squid_rn_refines(netmask, tt->rn_mask) ||
rn_lexobetter(netmask, tt->rn_mask))))
break;
on2:
/* Add new route to highest possible ancestor's list */
if ((netmask == 0) || (b > t->rn_b))
- return tt; /* can't lift at all */
+ return tt; /* can't lift at all */
b_leaf = tt->rn_b;
do {
x = t;
if (tt->rn_flags & RNF_NORMAL) {
if (m->rm_leaf != tt || m->rm_refs > 0) {
fprintf(stderr, "squid_rn_delete: inconsistent annotation\n");
- return 0; /* dangling ref could cause disaster */
+ return 0; /* dangling ref could cause disaster */
}
} else {
if (m->rm_mask != tt->rn_mask) {
b = -1 - tt->rn_b;
t = saved_tt->rn_p;
if (b > t->rn_b)
- goto on1; /* Wasn't lifted at all */
+ goto on1; /* Wasn't lifted at all */
do {
x = t;
t = t->rn_p;
if (m == 0) {
fprintf(stderr, "squid_rn_delete: couldn't find our annotation\n");
if (tt->rn_flags & RNF_NORMAL)
- return (0); /* Dangling ref to us */
+ return (0); /* Dangling ref to us */
}
on1:
/*
exit(-1);
}
}
+