I am waiting for homework requirement to stablize(even unstable rust are more stable than this)
This commit is contained in:
parent
406e6052ce
commit
d9c777a478
BIN
homework_11
BIN
homework_11
Binary file not shown.
30
src/main.c
30
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
1
src/v1.c
1
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);
|
||||
}
|
||||
|
|
58
src/v2.c
58
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");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue