search refactor

This commit is contained in:
hladu357 2024-06-09 20:11:44 +02:00
parent f278d1a799
commit 7cab4db54a
1 changed files with 24 additions and 13 deletions

View File

@ -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) { int radix_search(radix_holder_t t, record_t r) {
radix_node_t iter; radix_node_t iter;
int ibit, ret; int ibit;
unsigned char b; unsigned char b;
int m;
unsigned long mask[2] = {0x01ul << 63, 0x00}; unsigned long mask[2] = {0x01ul << 63, 0x00};
if (!r) if (!r)
@ -137,18 +138,27 @@ int radix_search(radix_holder_t t, record_t r) {
continue; continue;
if (ibit < iter->_data._mask) { /* bit mismatch */ 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 */ /* mask ends with full match */
ret = r->_rule = iter->_data._rule != INVALID_RULE ? iter->_data._rule : INVALID_RULE; if (iter->_data._rule != INVALID_RULE) {
iter = b ? iter->_l : iter->_r; r->_rule = iter->_data._rule;
if (!iter) m = iter->_data._mask;
return ret;
} }
ret = r->_rule = iter->_data._rule != INVALID_RULE ? iter->_data._rule : INVALID_RULE; iter = b ? iter->_l : iter->_r;
return ret; if (!iter)
return r->_rule;
}
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 RULES_FILE "../data/routing-data"
#define TEST_FILE "../data/test-data" #define TEST_FILE "../data/test-data"
#define TEST_ROWS 20 /*66319*/ #define TEST_ROWS 6286
#define READ_MODE "r" #define READ_MODE "r"
int parse_line(FILE* f, record_t 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 fire_tests(radix_holder_t t, struct routing_record* r) {
int row; int row;
int wrong = 0; int wrong = TEST_ROWS;
unsigned short ref_pop; unsigned short ref_pop;
for (row = 0; row < TEST_ROWS; ++row, ++r) { for (row = 0; row < TEST_ROWS; ++row, ++r) {
ref_pop = r->_rule; ref_pop = r->_rule;
r->_rule = INVALID_RULE;
radix_search(t, r); 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 ); printf("ref: %d got: %d @ %d\n", ref_pop, r->_rule, row );
++wrong;
}
} }
/* /*