search refactor
This commit is contained in:
parent
f278d1a799
commit
7cab4db54a
|
@ -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)
|
||||
|
@ -137,18 +138,27 @@ int radix_search(radix_holder_t t, record_t r) {
|
|||
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;
|
||||
iter = b ? iter->_l : iter->_r;
|
||||
if (!iter)
|
||||
return ret;
|
||||
if (iter->_data._rule != INVALID_RULE) {
|
||||
r->_rule = iter->_data._rule;
|
||||
m = iter->_data._mask;
|
||||
}
|
||||
|
||||
ret = r->_rule = iter->_data._rule != INVALID_RULE ? iter->_data._rule : INVALID_RULE;
|
||||
return ret;
|
||||
iter = b ? iter->_l : iter->_r;
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue