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()
|
int main()
|
||||||
{
|
{
|
||||||
struct State state;
|
// struct State state;
|
||||||
state.head=NULL;
|
// state.head=NULL;
|
||||||
|
|
||||||
input(&state);
|
// input(&state);
|
||||||
// length_distribution(&state);
|
// length_distribution(&state);
|
||||||
segment(&state);
|
// segment(&state);
|
||||||
// prefix_insert(&state);
|
// prefix_insert(&state);
|
||||||
// prefix_delete(&state);
|
// prefix_delete(&state);
|
||||||
// search(&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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,9 +72,12 @@ struct SizedSubmask* clone_submask(struct SizedSubmask *mask){
|
||||||
bool reduce_submask(struct SizedSubmask* source){
|
bool reduce_submask(struct SizedSubmask* source){
|
||||||
if(source->len<D)return false;
|
if(source->len<D)return false;
|
||||||
|
|
||||||
|
|
||||||
u32 mask=source->mask.raw;
|
u32 mask=source->mask.raw;
|
||||||
source->len=D;
|
source->len=D;
|
||||||
source->mask.raw=((mask>>(32-D))<<(32-D));
|
source->mask.raw=((mask>>(32-D))<<(32-D));
|
||||||
|
// display_submask(source);
|
||||||
|
// printf("\n");
|
||||||
return true;
|
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));
|
struct SizedSubmask* mask=malloc(sizeof(struct SizedSubmask));
|
||||||
parse_submask(buffer,mask);
|
parse_submask(buffer,mask);
|
||||||
if(mask<10000)printf("%zu\n",mask);
|
|
||||||
|
|
||||||
state->head=xor_insert_mid(NULL,state->head,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.len=D;
|
||||||
mask.mask.raw=i<<(32-D);
|
mask.mask.raw=i<<(32-D);
|
||||||
|
|
||||||
struct Node* head=hash_get(state->hashmap,&mask);
|
// struct Node* head=hash_get(state->hashmap,&mask);
|
||||||
printf("The number of prefixes in group %zu = %zu\n",i,xor_count(head));
|
// printf("The number of prefixes in group %zu = %zu\n",i,xor_count(head));
|
||||||
// printf("| ");
|
printf("| ");
|
||||||
// print_binary(i);
|
print_binary(i);
|
||||||
// printf(" |");
|
printf(" |");
|
||||||
|
|
||||||
// struct Node* current=hash_get(state->hashmap,&mask);
|
struct Node* current=hash_get(state->hashmap,&mask);
|
||||||
// struct Node* previous=NULL;
|
struct Node* previous=NULL;
|
||||||
|
|
||||||
// while(current!=NULL){
|
while(current!=NULL){
|
||||||
// struct Node* next=xor_next(previous,current);
|
struct Node* next=xor_next(previous,current);
|
||||||
|
|
||||||
// printf(" ---> | ");
|
printf(" ---> | ");
|
||||||
// display_ip(current->val);
|
display_ip(current->val);
|
||||||
// printf(" |");
|
printf(" |");
|
||||||
|
|
||||||
// previous=current;
|
previous=current;
|
||||||
// current=next;
|
current=next;
|
||||||
// }
|
}
|
||||||
// printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// {
|
{
|
||||||
// printf("--------special group--------\n");
|
printf("--------special group--------\n");
|
||||||
|
|
||||||
// struct Node* current=state->head;
|
struct Node* current=state->head;
|
||||||
// struct Node* previous=NULL;
|
struct Node* previous=NULL;
|
||||||
|
|
||||||
// while(current!=NULL){
|
while(current!=NULL){
|
||||||
// struct Node* next=xor_next(previous,current);
|
struct Node* next=xor_next(previous,current);
|
||||||
|
|
||||||
// display_ip(current->val);
|
display_ip(current->val);
|
||||||
// printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
// previous=current;
|
previous=current;
|
||||||
// current=next;
|
current=next;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// printf("-----------------------------\n");
|
printf("-----------------------------\n");
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue