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) {
|
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)
|
||||||
|
@ -132,23 +133,32 @@ int radix_search(radix_holder_t t, record_t r) {
|
||||||
|
|
||||||
for (ibit = 0; ibit < r->_mask; ++ibit, SHIFT_MASK(mask)) {
|
for (ibit = 0; ibit < r->_mask; ++ibit, SHIFT_MASK(mask)) {
|
||||||
b = GET_BIT(r->_ip, 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))
|
b == GET_BIT(iter->_data._ip, mask))
|
||||||
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) {
|
||||||
|
r->_rule = iter->_data._rule;
|
||||||
|
m = iter->_data._mask;
|
||||||
|
}
|
||||||
|
|
||||||
iter = b ? iter->_l : iter->_r;
|
iter = b ? iter->_l : iter->_r;
|
||||||
if (!iter)
|
if (!iter)
|
||||||
return ret;
|
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;
|
||||||
|
|
||||||
ret = r->_rule = iter->_data._rule != INVALID_RULE ? iter->_data._rule : INVALID_RULE;
|
return r->_rule;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue