macro cleanup
This commit is contained in:
		
							parent
							
								
									eccff7691f
								
							
						
					
					
						commit
						62f174b9c9
					
				
							
								
								
									
										14
									
								
								trie/trie.c
								
								
								
								
							
							
						
						
									
										14
									
								
								trie/trie.c
								
								
								
								
							|  | @ -1,13 +1,9 @@ | ||||||
| #include "trie.h" | #include "trie.h" | ||||||
| 
 | 
 | ||||||
| #define RULES_FILE "../data/routing-data" |  | ||||||
| #define TEST_FILE "../data/test-data" |  | ||||||
| #define TEST_ROWS 11 /*17217*/ |  | ||||||
| #define READ_MODE "r" | #define READ_MODE "r" | ||||||
| #define RULE_NOT_FOUND -1 | #define RULE_NOT_FOUND -1 | ||||||
| #define GET_BIT(key, bit) ( ( key.s[ bit / 16 ] & (1u << (15 - bit % 16)) ) != 0 ) | #define GET_BIT(key, bit) ( ( key.s[ bit / 16 ] & (1u << (15 - bit % 16)) ) != 0 ) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| trie_node_t create_node() { | trie_node_t create_node() { | ||||||
|     trie_node_t ret = calloc(1, sizeof(struct trie_node)); /* sets null childs and invalid */ |     trie_node_t ret = calloc(1, sizeof(struct trie_node)); /* sets null childs and invalid */ | ||||||
|     return ret; |     return ret; | ||||||
|  | @ -57,8 +53,7 @@ int trie_insert(trie_holder_t t, ipv6_t key, int val, int mask) { | ||||||
| 
 | 
 | ||||||
|     iter->_rule_valid = VALID_RULE; |     iter->_rule_valid = VALID_RULE; | ||||||
|     iter->_rule = val; |     iter->_rule = val; | ||||||
| 
 |     return ++t->_size;; | ||||||
|     return 1; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int trie_search(trie_holder_t t, ipv6_t key) { | int trie_search(trie_holder_t t, ipv6_t key) { | ||||||
|  | @ -81,12 +76,15 @@ int trie_search(trie_holder_t t, ipv6_t key) { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| /*--------------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------------*/ | ||||||
| /*                             TESTING                                            */ | /*                             TESTING                                            */ | ||||||
| /*--------------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------------*/ | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| 
 | 
 | ||||||
|  | #define RULES_FILE "../data/routing-data" | ||||||
|  | #define TEST_FILE "../data/test-data" | ||||||
|  | #define TEST_ROWS 5721 | ||||||
|  | 
 | ||||||
| int parse_line(ipv6_t* key, int* val, int* mask, FILE* f) { /*! assumes only good input */ | int parse_line(ipv6_t* key, int* val, int* mask, FILE* f) { /*! assumes only good input */ | ||||||
|     memset(key, 0, sizeof(ipv6_t)); |     memset(key, 0, sizeof(ipv6_t)); | ||||||
| 
 | 
 | ||||||
|  | @ -157,7 +155,7 @@ int fire_tests(trie_holder_t t, ipv6_t* ips, int* ref, int num_tests ) { | ||||||
| 
 | 
 | ||||||
|     for (row = 0; row < TEST_ROWS; ++ row) { |     for (row = 0; row < TEST_ROWS; ++ row) { | ||||||
|         if (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 ); |             printf("ref: %d got: %d @ %d\n", ref[row], trie_search(t, ips[row]), row ); | ||||||
|         ++wrong; |         ++wrong; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue