endianness independent now
This commit is contained in:
parent
19304a2c57
commit
9e91d8f826
29
trie/trie.c
29
trie/trie.c
|
@ -1,11 +1,11 @@
|
|||
#include "trie.h"
|
||||
#include <assert.h>
|
||||
|
||||
#define RULES_FILE "../data/routing-data"
|
||||
#define TEST_FILE "../data/test-data"
|
||||
#define TEST_ROWS 17217
|
||||
#define TEST_ROWS 70 /*17217*/
|
||||
#define READ_MODE "r"
|
||||
#define GET_BIT(key, bit) ( ( key.l[ bit / 64 ] & (1ul << (bit % 64)) ) != 0 )
|
||||
#define RULE_NOT_FOUND -1
|
||||
#define GET_BIT(key, bit) ( ( key.s[ bit / 16 ] & (1ul << (15 - bit % 16)) ) != 0 )
|
||||
|
||||
|
||||
trie_node_t create_node() {
|
||||
|
@ -51,7 +51,7 @@ int trie_search(trie_holder_t t, ipv6_t key) {
|
|||
trie_node_t iter = t->_root;
|
||||
trie_node_t next;
|
||||
int i = 0;
|
||||
int ret = -1;
|
||||
int ret = RULE_NOT_FOUND;
|
||||
|
||||
for (;i < 128; ++i) {
|
||||
if (iter->_rule_valid)
|
||||
|
@ -66,9 +66,13 @@ int trie_search(trie_holder_t t, ipv6_t key) {
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
/* TESTING */
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
#include <assert.h>
|
||||
|
||||
int parse_line(ipv6_t* key, int* val, int* mask, FILE* f) { /*! assumes only good input */
|
||||
memset(key, 0, sizeof(ipv6_t));
|
||||
|
||||
|
@ -121,6 +125,7 @@ int load_tests(ipv6_t** rips, int** rref) {
|
|||
&ips[row].s[0], &ips[row].s[1], &ips[row].s[2], &ips[row].s[3],
|
||||
&ips[row].s[4], &ips[row].s[5], &ips[row].s[6], &ips[row].s[7]);
|
||||
|
||||
|
||||
while (fgetc(f) != ' ');
|
||||
fscanf(f, "%d", &(ref[row]));
|
||||
}
|
||||
|
@ -132,11 +137,16 @@ int load_tests(ipv6_t** rips, int** rref) {
|
|||
|
||||
int fire_tests(trie_holder_t t, ipv6_t* ips, int* ref, int num_tests ) {
|
||||
int row;
|
||||
int wrong = 0;
|
||||
|
||||
for (row = 0; row < TEST_ROWS; ++ row) {
|
||||
printf("%d %d\n", trie_search(t, ips[row]), ref[row] );
|
||||
if (trie_search(t, ips[row]) != ref[row]) {
|
||||
printf("%d %d @ %d\n", trie_search(t, ips[row]), ref[row], row );
|
||||
++wrong;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return wrong;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@ -146,9 +156,8 @@ int main() {
|
|||
trie_holder_t t = create_holder();
|
||||
printf("Loaded %d rules\n", load_input(t) );
|
||||
printf("Loaded %d tests\n", load_tests(&ips, &ref) );
|
||||
/*
|
||||
fire_tests(t, ips, ref, TEST_ROWS);
|
||||
*/
|
||||
printf("%d tests wrong\n", fire_tests(t, ips, ref, TEST_ROWS) );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue