diff options
author | Daniel Silverstone <dsilvers@netsurf-browser.org> | 2007-06-10 17:46:44 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@netsurf-browser.org> | 2007-06-10 17:46:44 +0000 |
commit | 1dd7e97eb3f2cd317ef64fa9c054aacba6499215 (patch) | |
tree | 3214739cb7769964e7def41eba60f938fd106a4b /utils/ring.h | |
parent | ccc270eea1acaf9a9eb7e0c3a6f289c9c844d129 (diff) | |
download | netsurf-1dd7e97eb3f2cd317ef64fa9c054aacba6499215.tar.gz netsurf-1dd7e97eb3f2cd317ef64fa9c054aacba6499215.tar.bz2 |
Merge scheme switcher branch in.
svn path=/trunk/netsurf/; revision=3330
Diffstat (limited to 'utils/ring.h')
-rw-r--r-- | utils/ring.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/utils/ring.h b/utils/ring.h new file mode 100644 index 000000000..31698cd46 --- /dev/null +++ b/utils/ring.h @@ -0,0 +1,98 @@ +/* + * This file is part of NetSurf, http://netsurf-browser.org/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006, 2007 Daniel Silverstone <dsilvers@digital-scurf.org> + */ + +/** \file + * Ring list structure. + * + * Rings are structures which have an r_next pointer and an r_prev + * pointer which are always initialised and always point at the next + * or previous element respectively. + * + * The degenerate case of a single element in the ring simply points + * at itself in both directions. A zero element ring is NULL. + * + * Some of the ring functions are specific to the fetcher but may be + * of use to others and are thus included here. + */ + +#ifndef _NETSURF_UTILS_RING_H_ +#define _NETSURF_UTILS_RING_H_ + + +/** Insert the given item into the specified ring. + * Assumes that the element is zeroed as appropriate. + */ +#define RING_INSERT(ring,element) \ + /*LOG(("RING_INSERT(%s, %p(%s))", #ring, element, element->host));*/ \ + if (ring) { \ + element->r_next = ring; \ + element->r_prev = ring->r_prev; \ + ring->r_prev = element; \ + element->r_prev->r_next = element; \ + } else \ + ring = element->r_prev = element->r_next = element + +/** Remove the given element from the specified ring. + * Will zero the element as needed + */ +#define RING_REMOVE(ring, element) \ + /*LOG(("RING_REMOVE(%s, %p(%s)", #ring, element, element->host));*/ \ + if (element->r_next != element ) { \ + /* Not the only thing in the ring */ \ + element->r_next->r_prev = element->r_prev; \ + element->r_prev->r_next = element->r_next; \ + if (ring == element) ring = element->r_next; \ + } else { \ + /* Only thing in the ring */ \ + ring = 0; \ + } \ + element->r_next = element->r_prev = 0 + +/** Find the element (by hostname) in the given ring, leave it in the + * provided element variable + */ +#define RING_FINDBYHOST(ring, element, hostname) \ + /*LOG(("RING_FINDBYHOST(%s, %s)", #ring, hostname));*/ \ + if (ring) { \ + bool found = false; \ + element = ring; \ + do { \ + if (strcasecmp(element->host, hostname) == 0) { \ + found = true; \ + break; \ + } \ + element = element->r_next; \ + } while (element != ring); \ + if (!found) element = 0; \ + } else element = 0 + +/** Measure the size of a ring and put it in the supplied variable */ +#define RING_GETSIZE(ringtype, ring, sizevar) \ + /*LOG(("RING_GETSIZE(%s)", #ring));*/ \ + if (ring) { \ + ringtype *p = ring; \ + sizevar = 0; \ + do { \ + sizevar++; \ + p = p->r_next; \ + } while (p != ring); \ + } else sizevar = 0 + +/** Count the number of elements in the ring which match the provided hostname */ +#define RING_COUNTBYHOST(ringtype, ring, sizevar, hostname) \ + /*LOG(("RING_COUNTBYHOST(%s, %s)", #ring, hostname));*/ \ + if (ring) { \ + ringtype *p = ring; \ + sizevar = 0; \ + do { \ + if (strcasecmp(p->host, hostname) == 0) \ + sizevar++; \ + p = p->r_next; \ + } while (p != ring); \ + } else sizevar = 0 + +#endif |