diff --git a/radix/radix.c b/radix/radix.c index b77be73..818a8a8 100644 --- a/radix/radix.c +++ b/radix/radix.c @@ -118,8 +118,9 @@ int radix_insert(radix_holder_t t, record_t /*restrict*/ r) { int radix_search(radix_holder_t t, record_t r) { radix_node_t iter; - int ibit, ret; + int ibit; unsigned char b; + int m; unsigned long mask[2] = {0x01ul << 63, 0x00}; if (!r) @@ -132,23 +133,32 @@ int radix_search(radix_holder_t t, record_t r) { for (ibit = 0; ibit < r->_mask; ++ibit, SHIFT_MASK(mask)) { b = GET_BIT(r->_ip, mask); - if (ibit < iter->_data._mask && /* bit match */ + if (ibit < iter->_data._mask && /* bit match */ b == GET_BIT(iter->_data._ip, mask)) continue; if (ibit < iter->_data._mask) { /* bit mismatch */ - return r->_rule = INVALID_RULE; + return r->_rule; + /* = ibit == iter->_data._mask ? iter->_data._rule : r->_rule; */ } /* mask ends with full match */ - ret = r->_rule = iter->_data._rule != INVALID_RULE ? iter->_data._rule : INVALID_RULE; + if (iter->_data._rule != INVALID_RULE) { + r->_rule = iter->_data._rule; + m = iter->_data._mask; + } + iter = b ? iter->_l : iter->_r; if (!iter) - return ret; + return r->_rule; } - - ret = r->_rule = iter->_data._rule != INVALID_RULE ? iter->_data._rule : INVALID_RULE; - return ret; + if (ibit == iter->_data._mask && iter->_data._rule != INVALID_RULE) { + r->_rule = iter->_data._rule; + m = iter->_data._mask; + } + r->_mask = m; + + return r->_rule; } @@ -161,7 +171,7 @@ int radix_search(radix_holder_t t, record_t r) { #define RULES_FILE "../data/routing-data" #define TEST_FILE "../data/test-data" -#define TEST_ROWS 20 /*66319*/ +#define TEST_ROWS 6286 #define READ_MODE "r" int parse_line(FILE* f, record_t r) { @@ -259,16 +269,17 @@ int load_tests(struct routing_record** ref) { int fire_tests(radix_holder_t t, struct routing_record* r) { int row; - int wrong = 0; + int wrong = TEST_ROWS; unsigned short ref_pop; for (row = 0; row < TEST_ROWS; ++row, ++r) { ref_pop = r->_rule; + r->_rule = INVALID_RULE; radix_search(t, r); - if ( ref_pop != r->_rule) { + if ( ref_pop == r->_rule) + --wrong; + else printf("ref: %d got: %d @ %d\n", ref_pop, r->_rule, row ); - ++wrong; - } } /*