]> jfr.im git - irc/quakenet/newserv.git/commitdiff
macros
authorPaul <redacted>
Mon, 31 Mar 2008 22:55:41 +0000 (23:55 +0100)
committerPaul <redacted>
Mon, 31 Mar 2008 22:55:41 +0000 (23:55 +0100)
patricia/patricia.h
patricia/patricialib.c

index 68fc4950472c4814ed86b2c7dbba6c597664985a..8ea603586a217e08e2a863a8d0025d04d7cddd89 100644 (file)
@@ -26,7 +26,6 @@ typedef void (*void_fn_t)();
 /* { from defs.h */
 #define prefix_touchar(prefix) ((u_char *)&(prefix)->sin)
 #define MAXLINE 1024
-#define BIT_TEST(f, b)  ((f) & (b))
 /* } */
 
 #include <sys/types.h> /* for u_* definitions (on FreeBSD 5) */
@@ -108,8 +107,11 @@ void freenode (patricia_node_t *node);
 patricia_node_t *refnode(patricia_tree_t *tree, struct irc_in_addr *sin, int bitlen);
 void derefnode(patricia_tree_t *tree, patricia_node_t *node);
 
+#define get_byte_for_bit(base, nr) (base)[(nr) >> 3]
+#define bigendian_bitfor(nr) (0x80 >> ((nr) & 0x07))
+#define is_bit_set(base, nr) (get_byte_for_bit(base, nr) & bigendian_bitfor(nr))
+
 #define PATRICIA_MAXBITS 128
-#define PATRICIA_NBYTE(x)       ((x) >> 3)
 
 #define PATRICIA_WALK(Xhead, Xnode) \
     do { \
index c9dcd4ef9395f1f29aac7dc1e793a85364b82b5d..a68fa552271a8ec94209598ea49155f4b407b904 100644 (file)
@@ -212,7 +212,7 @@ patricia_search_exact (patricia_tree_t *patricia, struct irc_in_addr *sin, unsig
     addr = (u_char *)sin;
 
     while (node->bit < bitlen) {
-       if (BIT_TEST (addr[node->bit >> 3], 0x80 >> (node->bit & 0x07)))
+        if (is_bit_set(addr,node->bit))
            node = node->r;
        else
            node = node->l;
@@ -257,7 +257,7 @@ patricia_search_best2 (patricia_tree_t *patricia, struct irc_in_addr *sin, unsig
            stack[cnt++] = node;
        }
 
-       if (BIT_TEST (addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) {
+        if (is_bit_set(addr,node->bit)) {
            node = node->r;
        }
        else {
@@ -320,7 +320,7 @@ patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
     while (node->bit < bitlen || node->prefix == NULL) {
         /* check that we're not at the lowest leaf i.e. node->bit is less than max bits */
        if (node->bit < patricia->maxbits &&
-           (addr[node->bit >> 3]) & (0x80 >> (node->bit & 0x07))) {
+            (is_bit_set(addr,node->bit))) {
            if (node->r == NULL)
                break;
            node = node->r;
@@ -377,7 +377,7 @@ patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
     if (node->bit == differ_bit) {
        new_node->parent = node;
        if (node->bit < patricia->maxbits &&
-           (addr[node->bit >> 3]) & (0x80 >> (node->bit & 0x07))) {
+           (is_bit_set(addr, node->bit))) {
            assert (node->r == NULL);
            node->r = new_node;
        }
@@ -390,7 +390,7 @@ patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
 
     if (bitlen == differ_bit) {
        if (bitlen < patricia->maxbits &&
-           (test_addr[bitlen >> 3]) & (0x80 >> (bitlen & 0x07))) {
+           (is_bit_set(addr,bitlen))) {
            new_node->r = node;
        }
        else {
@@ -414,7 +414,7 @@ patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
         glue->parent = node->parent;
         
        if (differ_bit < patricia->maxbits &&
-           (addr[differ_bit >> 3]) & (0x80 >> (differ_bit & 0x07))) {
+           (is_bit_set(addr, differ_bit))) {
            glue->r = new_node;
            glue->l = node;
        }