diff --git a/homework_11 b/homework_11 index 962d8eb..5aa97ef 100755 Binary files a/homework_11 and b/homework_11 differ diff --git a/src/main.c b/src/main.c index d93c64f..f77522a 100644 --- a/src/main.c +++ b/src/main.c @@ -9,15 +9,37 @@ int main() { - struct State state; - state.head=NULL; + // struct State state; + // state.head=NULL; - input(&state); + // input(&state); // length_distribution(&state); - segment(&state); + // segment(&state); // prefix_insert(&state); // prefix_delete(&state); // search(&state); + + FILE * table = fopen("routing_table.txt","r"); + usize amount=0; + usize store[256]; + + for(usize i=0;i<256;i++)store[i]=0; + + while(true){ + char buffer[20]={'\0'}; + fgets(buffer,20,table); + if(*buffer=='\0') break; + + amount++; + + struct SizedSubmask mask; + parse_submask(buffer,&mask); + if(reduce_submask(&mask)) store[mask.mask.mask[3]]++; + + } + printf("The total number of prefixes in the input file is : %zu.\n",amount); + + for(usize i=0;i<256;i++)printf("The number of prefixes in group %zu = %zu\n",i,store[i]); return 0; } diff --git a/src/state.c b/src/state.c index 09d760e..5d989e5 100644 --- a/src/state.c +++ b/src/state.c @@ -71,10 +71,13 @@ struct SizedSubmask* clone_submask(struct SizedSubmask *mask){ bool reduce_submask(struct SizedSubmask* source){ if(source->len<D)return false; + u32 mask=source->mask.raw; source->len=D; source->mask.raw=((mask>>(32-D))<<(32-D)); + // display_submask(source); + // printf("\n"); return true; } diff --git a/src/v1.c b/src/v1.c index c849463..c418799 100644 --- a/src/v1.c +++ b/src/v1.c @@ -18,7 +18,6 @@ void input(struct State* state){ struct SizedSubmask* mask=malloc(sizeof(struct SizedSubmask)); parse_submask(buffer,mask); - if(mask<10000)printf("%zu\n",mask); state->head=xor_insert_mid(NULL,state->head,mask); } diff --git a/src/v2.c b/src/v2.c index 76921b4..559176b 100644 --- a/src/v2.c +++ b/src/v2.c @@ -60,45 +60,45 @@ void segment(struct State* state){ mask.len=D; mask.mask.raw=i<<(32-D); - struct Node* head=hash_get(state->hashmap,&mask); - printf("The number of prefixes in group %zu = %zu\n",i,xor_count(head)); - // printf("| "); - // print_binary(i); - // printf(" |"); + // struct Node* head=hash_get(state->hashmap,&mask); + // printf("The number of prefixes in group %zu = %zu\n",i,xor_count(head)); + printf("| "); + print_binary(i); + printf(" |"); - // struct Node* current=hash_get(state->hashmap,&mask); - // struct Node* previous=NULL; + struct Node* current=hash_get(state->hashmap,&mask); + struct Node* previous=NULL; - // while(current!=NULL){ - // struct Node* next=xor_next(previous,current); + while(current!=NULL){ + struct Node* next=xor_next(previous,current); - // printf(" ---> | "); - // display_ip(current->val); - // printf(" |"); + printf(" ---> | "); + display_ip(current->val); + printf(" |"); - // previous=current; - // current=next; - // } - // printf("\n"); + previous=current; + current=next; + } + printf("\n"); } - // { - // printf("--------special group--------\n"); + { + printf("--------special group--------\n"); - // struct Node* current=state->head; - // struct Node* previous=NULL; + struct Node* current=state->head; + struct Node* previous=NULL; - // while(current!=NULL){ - // struct Node* next=xor_next(previous,current); + while(current!=NULL){ + struct Node* next=xor_next(previous,current); - // display_ip(current->val); - // printf("\n"); + display_ip(current->val); + printf("\n"); - // previous=current; - // current=next; - // } + previous=current; + current=next; + } - // printf("-----------------------------\n"); - // } + printf("-----------------------------\n"); + } } \ No newline at end of file